public static void basic_distance_test() { var line = new Line2(new Point2(1, 1), new Vector2(2, 1)); var targetA = new Point2(-1, 0); var targetB = new Point2(.5, 2); var distanceA = line.Distance(targetA); var distanceB = line.Distance(targetB); distanceA.Should().Be(0); distanceB.Should().Be(System.Math.Sqrt((0.5 * 0.5) + 1.0)); }
public override double DistanceTo(IRelevantObject relevantObject) { if (!(relevantObject is RelevantLine relevantLine)) { return(double.PositiveInfinity); } var cosAlpha = Vector2.Dot(Child.DirectionVector, relevantLine.Child.DirectionVector) / (Child.DirectionVector.Length * relevantLine.Child.DirectionVector.Length); // This is the length of the opposite side in a right triangle with an adjacent side length of 100 var angleDiff = Math.Sqrt(10000 / (cosAlpha * cosAlpha) - 10000); return(Line2.Distance(Child, relevantLine.Child.PositionVector) + angleDiff); }
public override bool Intersection(IRelevantObject other, out Vector2[] intersections) { intersections = new[] { Child }; switch (other) { case RelevantPoint point: return(Precision.AlmostEquals(point.Child.X, Child.X) & Precision.AlmostEquals(point.Child.Y, Child.Y)); case RelevantLine line: return(Precision.AlmostEquals(Line2.Distance(line.Child, Child), 0)); case RelevantCircle circle: return(Precision.AlmostEquals(Vector2.Distance(circle.Child.Centre, Child), circle.Child.Radius)); default: return(false); } }
public override bool Intersection(IRelevantObject other, out Vector2[] intersections) { switch (other) { case RelevantPoint point: intersections = new[] { point.Child }; return(Precision.AlmostEquals(Line2.Distance(Child, point.Child), 0)); case RelevantLine line: { bool isIntersecting = Line2.Intersection(Child, line.Child, out var intersection); intersections = new[] { intersection }; return(isIntersecting); } case RelevantCircle circle: return(Circle.Intersection(circle.Child, Child, out intersections)); default: intersections = new Vector2[0]; return(false); } }
public override double DistanceTo(Vector2 point) { return(Line2.Distance(Child, point)); }