예제 #1
0
        public void StaticIntersectionTest(double firstOriginX, double firstOriginY, double firstDirectionX, double firstDirectionY,
                                           double secondOriginX, double secondOriginY, double secondDirectionX, double secondDirectionY, double resultX, double resultY)
        {
            var firstRay  = new Ray2D(new Point2D(firstOriginX, firstOriginY), new Vector2D(firstDirectionX, firstDirectionY));
            var secondRay = new Ray2D(new Point2D(secondOriginX, secondOriginY), new Vector2D(secondDirectionX, secondDirectionY));

            var intersectionPoint = Ray2D.Intersection(firstRay, secondRay);

            if (resultX == double.PositiveInfinity || resultY == double.PositiveInfinity)
            {
                Assert.AreEqual(null, intersectionPoint);
            }
            else
            {
                Assert.AreEqual(resultX, intersectionPoint.X, Helper.E);
                Assert.AreEqual(resultY, intersectionPoint.Y, Helper.E);
            }

            var intersectionPoint2 = Ray2D.Intersection(secondRay, firstRay);

            if (resultX == double.PositiveInfinity || resultY == double.PositiveInfinity)
            {
                Assert.AreEqual(null, intersectionPoint2);
            }
            else
            {
                Assert.AreEqual(resultX, intersectionPoint2.X, Helper.E);
                Assert.AreEqual(resultY, intersectionPoint2.Y, Helper.E);
            }
        }
예제 #2
0
        public IEnumerable <Point2D> Intersections(List <Ray2D> rays)
        {
            var results = new List <Point2D>();

            for (var i = 0; i < rays.Count - 1; i++)
            {
                for (var j = i + 1; j < rays.Count; j++)
                {
                    results.Add(Ray2D.Intersection(rays[i], rays[j]));
                }
            }

            return(results);
        }
예제 #3
0
        public static Point?GetNearest(Circle2D c, Point p)
        {
            Ray2D r = new Ray2D(c.Center, p);

            return(GetNearest(r.Intersection(c), p));
        }