public void CalculateGrazeLineSphereIntersection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(0, 0); var lineEndPoint = new Point(300, 286.179770816163); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(1, intersection); Assert.IsNotNull(firstIntersection); Assert.AreEqual(153.45121834340819, firstIntersection.Value.X, 0.00001); Assert.AreEqual(146.38211498992513, firstIntersection.Value.Y, 0.00001); Assert.IsNull(secondIntersection); }
public void CalculateLineSphereIntersectionWithOppositeDirection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(140, 140); var lineEndPoint = new Point(0, 0); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(0, intersection); Assert.IsNull(firstIntersection); Assert.IsNull(secondIntersection); }
public void CalculateRunThroughLineSphereIntersection() { // arrange var sphereCenter = new Point(150, 150); const double SphereRadius = 5; var lineStartPoint = new Point(0, 0); var lineEndPoint = new Point(300, 300); Point?firstIntersection; Point?secondIntersection; // act var intersection = CalculationHelpers.CalculateLineSphereIntersection( sphereCenter, SphereRadius, lineStartPoint, lineEndPoint, out firstIntersection, out secondIntersection); // assert Assert.AreEqual(2, intersection); Assert.IsNotNull(firstIntersection); Assert.AreEqual(146.4644660940672624, firstIntersection.Value.X, 0.00001); Assert.AreEqual(146.4644660940672624, firstIntersection.Value.Y, 0.00001); Assert.IsNotNull(secondIntersection); Assert.AreEqual(153.5355339059327376, secondIntersection.Value.X, 0.00001); Assert.AreEqual(153.5355339059327376, secondIntersection.Value.Y, 0.00001); }