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); } }
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); }
public static Point?GetNearest(Circle2D c, Point p) { Ray2D r = new Ray2D(c.Center, p); return(GetNearest(r.Intersection(c), p)); }