当前位置: 首页>>代码示例>>C#>>正文


C# Ray.FirstIntersectionWith方法代码示例

本文整理汇总了C#中Ray.FirstIntersectionWith方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.FirstIntersectionWith方法的具体用法?C# Ray.FirstIntersectionWith怎么用?C# Ray.FirstIntersectionWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray.FirstIntersectionWith方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FirstIntersectionWithCircleFromOutsideRoundtrips

 public void FirstIntersectionWithCircleFromOutsideRoundtrips(string cs)
 {
     var circle = Circle.Parse(cs);
     var xv = new Vector(1, 0);
     for (var i = -180; i < 180; i++)
     {
         var direction = xv.Rotate(i);
         var pointOnCircumference = circle.PointOnCircumference(direction);
         var ray = new Ray(pointOnCircumference + direction, direction.Negated());
         var actual = ray.FirstIntersectionWith(circle);
         Assert.Equal(pointOnCircumference, actual, NullablePointComparer.Default);
     }
 }
开发者ID:JohanLarsson,项目名称:Gu.Wpf.Geometry,代码行数:13,代码来源:RayTests.cs

示例2: FirstIntersectionWithEllipseFromInsideRoundtrips

 public void FirstIntersectionWithEllipseFromInsideRoundtrips(string es)
 {
     var ellipse = Ellipse.Parse(es);
     var xv = new Vector(1, 0);
     for (var i = -180; i < 180; i++)
     {
         var direction = xv.Rotate(i);
         var expected = ellipse.PointOnCircumference(direction);
         var ray = new Ray(ellipse.CenterPoint, direction);
         var actual = ray.FirstIntersectionWith(ellipse);
         Assert.Equal(expected, actual, NullablePointComparer.Default);
     }
 }
开发者ID:JohanLarsson,项目名称:Gu.Wpf.Geometry,代码行数:13,代码来源:RayTests.cs

示例3: FirstIntersectionWithRectFromOutsideRoundtrips

        public void FirstIntersectionWithRectFromOutsideRoundtrips(string rs)
        {
            var rect = Rect.Parse(rs);
            var xAxis = new Vector(1, 0);
            for (var i = -180; i < 180; i++)
            {
                var direction = xAxis.Rotate(i);
                var fromCenter = new Ray(rect.CenterPoint(), direction);
                var pointOnRect = fromCenter.FirstIntersectionWith(rect).GetValueOrDefault();
                var ray = new Ray(pointOnRect + direction, direction.Negated());
                var actual = ray.FirstIntersectionWith(rect);
                Assert.Equal(pointOnRect, actual, NullablePointComparer.Default);

                if (rect.ClosestCornerPoint(pointOnRect)
                        .DistanceTo(pointOnRect) < 0.01)
                {
                    continue;
                }

                Vector wallNormal;

                if (Math.Abs(pointOnRect.X - rect.Left) < Constants.Tolerance)
                {
                    wallNormal = new Vector(-1, 0);
                }
                else if(Math.Abs(pointOnRect.X - rect.Right) < Constants.Tolerance)
                {
                    wallNormal = new Vector(1, 0);
                }
                else if (Math.Abs(pointOnRect.Y - rect.Bottom) < Constants.Tolerance)
                {
                    wallNormal = new Vector(0, 1);
                }
                else // if (pointOnRect.Y == rect.Top)
                {
                    wallNormal = new Vector(0, -1);
                }

                for (var j = -89; j < 89; j++)
                {
                    var rayDirection = wallNormal.Rotate(j);
                    ray = new Ray(pointOnRect + rayDirection, rayDirection.Negated());
                    actual = ray.FirstIntersectionWith(rect);
                    if (!NullablePointComparer.Default.Equals(pointOnRect, actual))
                    {
                        Debugger.Break();
                    }

                    Assert.Equal(pointOnRect, actual, NullablePointComparer.Default);
                }
            }
        }
开发者ID:JohanLarsson,项目名称:Gu.Wpf.Geometry,代码行数:52,代码来源:RayTests.cs

示例4: FirstIntersectionWithEllipseFromOutsideRoundtrips

 public void FirstIntersectionWithEllipseFromOutsideRoundtrips(string es)
 {
     var ellipse = Ellipse.Parse(es);
     var xv = new Vector(1, 0);
     for (var i = -180; i < 180; i++)
     {
         var fromCenterDirection = xv.Rotate(i);
         var pointOnCircumference = ellipse.PointOnCircumference(fromCenterDirection);
         var ray = new Ray(pointOnCircumference + fromCenterDirection, fromCenterDirection.Negated());
         var actual = ray.FirstIntersectionWith(ellipse);
         Assert.Equal(pointOnCircumference, actual, NullablePointComparer.Default);
         for (var j = -70; j < 70; j++)
         {
             var direction = fromCenterDirection.Rotate(j);
             ray = new Ray(pointOnCircumference + direction, direction.Negated());
             actual = ray.FirstIntersectionWith(ellipse);
             //if (!NullablePointComparer.Default.Equals(pointOnCircumference, actual))
             //{
             //    Debugger.Break();
             //}
             Assert.Equal(pointOnCircumference, actual, NullablePointComparer.Default);
         }
     }
 }
开发者ID:JohanLarsson,项目名称:Gu.Wpf.Geometry,代码行数:24,代码来源:RayTests.cs


注:本文中的Ray.FirstIntersectionWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。