public static void Initialization() { CircularCurve curve1 = new CircularCurve(new CartesianCoordinate(1, 2), new CartesianCoordinate(3, 4)); CircularCurve curve2 = new CircularCurve(new CartesianCoordinate(-1, 2), new CartesianCoordinate(-3, 4)); IntersectionCircularCircular intersections = new IntersectionCircularCircular(curve1, curve2); Assert.AreEqual(curve1, intersections.Curve1); Assert.AreEqual(curve2, intersections.Curve2); }
[TestCase(4, -5, 6, 13.5262794416288, -10.5, 3)] // No intersection, Translated and Rotated to quadrant 4 public static void IntersectionCoordinates_Static_of_Not_Intersecting_Returns_Empty_Array( double x1, double y1, double r1, double x2, double y2, double r2) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; CartesianCoordinate[] intersectionCoordinates = IntersectionCircularCircular.IntersectionCoordinates(curve1, curve2); Assert.AreEqual(0, intersectionCoordinates.Length); }
[TestCase(0, 0, 6, 0, 0, 6)] // Circles overlap, same sizes public static void RadicalLineLength_Throws_OverlappingCurvesException_when_No_Separation( double x1, double y1, double r1, double x2, double y2, double r2) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; IntersectionCircularCircular intersections = new IntersectionCircularCircular(curve1, curve2); Assert.Throws <OverlappingCurvesException>(() => intersections.RadicalLineLength()); }
/// <summary> /// Initializes a new instance of the <see cref="IntersectionProperties"/> class. /// </summary> /// <param name="linearCurve">The linear curve.</param> /// <param name="circularCurve">The circular curve.</param> public IntersectionProperties(LinearCurve linearCurve, CircularCurve circularCurve) { Tolerance = Generics.GetTolerance(linearCurve, circularCurve); Transformations = new Transformations(circularCurve.LocalOrigin, new CartesianCoordinate(circularCurve.LocalOrigin.X + 1, circularCurve.LocalOrigin.Y)); LinearCurve linearCurveLocal = transformToLocal(linearCurve); D = Numbers.ValueAsZeroIfWithinAbsoluteTolerance(linearCurveLocal.ControlPointI.CrossProduct(linearCurveLocal.ControlPointJ), Tolerance); CartesianOffset offset = linearCurveLocal.Range.End.Limit.OffsetFrom(linearCurveLocal.Range.Start.Limit); dx = offset.X(); dy = offset.Y(); dr = AlgebraLibrary.SRSS(dx, dy); IncidenceDelta = Numbers.ValueAsZeroIfWithinAbsoluteTolerance((circularCurve.Radius * dr).Squared() - D.Squared(), Tolerance); }
[TestCase(4, 5, 6, 13.5262794416288, 10.5, 7, true)] // Intersection, Translated and Rotated to quadrant 1 public static void AreIntersecting_Static( double x1, double y1, double r1, double x2, double y2, double r2, bool expectedResult) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; bool result = IntersectionCircularCircular.AreIntersecting(curve1, curve2); Assert.AreEqual(expectedResult, result); }
[TestCase(5, 13, 12, 6, 5, 6, 6, false)] // Sloped Intersection in translated coordinates public static void AreTangent_Static( double x1, double y1, double x2, double y2, double x, double y, double r, bool expectedResult) { LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y)); curve2.Tolerance = Tolerance; bool result = IntersectionLinearCircular.AreTangent(curve1, curve2); Assert.AreEqual(expectedResult, result); }
[TestCase(0, 0, 6, 0, 0, 3, 0)] // Circles overlap public static void CenterSeparations_Static_Returns_Distance_Circle_Centers_Are_Separated_By( double x1, double y1, double r1, double x2, double y2, double r2, double expected) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; double result = IntersectionCircularCircular.CenterSeparations(curve1, curve2); Assert.AreEqual(expected, result, Tolerance); }
[TestCase(4, -5, 6, 13.5262794416288, -10.5, 7, 6.899515)] // Intersection, Translated and Rotated to quadrant 4 public static void RadicalLineLength_Returns_Length_of_Radical_Line_Formed_By_Circular_Intersection( double x1, double y1, double r1, double x2, double y2, double r2, double expected) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; IntersectionCircularCircular intersections = new IntersectionCircularCircular(curve1, curve2); double result = intersections.RadicalLineLength(); Assert.AreEqual(expected, result, Tolerance); }
[TestCase(4, -5, 6, 13.5262794416288, -10.5, 5, 9.196152, -8)] // Tangent, Translated and Rotated to quadrant 4 public static void IntersectionCoordinates_Static_of_Tangents_Returns_Tangent_Coordinate( double x1, double y1, double r1, double x2, double y2, double r2, double x1Expected, double y1Expected) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; CartesianCoordinate[] intersectionCoordinates = IntersectionCircularCircular.IntersectionCoordinates(curve1, curve2); Assert.AreEqual(1, intersectionCoordinates.Length); Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance); Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance); }
[TestCase(5, 16, 15, 6, 5, 6, 6)] // No Intersection in translated coordinates public static void IntersectionCoordinates_of_Not_Intersecting_Returns_Empty_Array( double x1, double y1, double x2, double y2, double x, double y, double r) { LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y)); curve2.Tolerance = Tolerance; IntersectionLinearCircular intersections = new IntersectionLinearCircular(curve1, curve2); CartesianCoordinate[] intersectionCoordinates = intersections.IntersectionCoordinates(); Assert.AreEqual(0, intersectionCoordinates.Length); }
[TestCase(5, 13, 12, 6, 5, 6, 6, 6.102084, 11.897916, 10.897916, 7.102084)] // Sloped Intersection in translated coordinates public static void IntersectionCoordinates_Static( double x1, double y1, double x2, double y2, double x, double y, double r, double x1Expected, double y1Expected, double x2Expected, double y2Expected) { LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y)); curve2.Tolerance = Tolerance; CartesianCoordinate[] intersectionCoordinates = IntersectionLinearCircular.IntersectionCoordinates(curve1, curve2); Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance); Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance); Assert.AreEqual(x2Expected, intersectionCoordinates[1].X, Tolerance); Assert.AreEqual(y2Expected, intersectionCoordinates[1].Y, Tolerance); }
[TestCase(5, 14.4852813742386, 13.4852813742386, 6, 5, 6, 6, 9.24264068711928, 10.2426406871193)] // Sloped Tangent in Quadrant 1 in translated coordinates public static void IntersectionCoordinates_of_Tangents_Returns_Tangent_Coordinate( double x1, double y1, double x2, double y2, double x, double y, double r, double x1Expected, double y1Expected) { LinearCurve curve1 = new LinearCurve(new CartesianCoordinate(x1, y1), new CartesianCoordinate(x2, y2)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r, new CartesianCoordinate(x, y)); curve2.Tolerance = Tolerance; IntersectionLinearCircular intersections = new IntersectionLinearCircular(curve1, curve2); CartesianCoordinate[] intersectionCoordinates = intersections.IntersectionCoordinates(); Assert.AreEqual(1, intersectionCoordinates.Length); Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance); Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance); }
[TestCase(4, -5, 6, 13.5262794416288, -10.5, 7, 9.976276, -4.466968, 6.526519, -10.442123)] // Intersection, Translated and Rotated to quadrant 4 public static void IntersectionCoordinates( double x1, double y1, double r1, double x2, double y2, double r2, double x1Expected, double y1Expected, double x2Expected, double y2Expected) { CircularCurve curve1 = new CircularCurve(r1, new CartesianCoordinate(x1, y1)); curve1.Tolerance = Tolerance; CircularCurve curve2 = new CircularCurve(r2, new CartesianCoordinate(x2, y2)); curve2.Tolerance = Tolerance; IntersectionCircularCircular intersections = new IntersectionCircularCircular(curve1, curve2); CartesianCoordinate[] intersectionCoordinates = intersections.IntersectionCoordinates(); Assert.AreEqual(x1Expected, intersectionCoordinates[0].X, Tolerance); Assert.AreEqual(y1Expected, intersectionCoordinates[0].Y, Tolerance); Assert.AreEqual(x2Expected, intersectionCoordinates[1].X, Tolerance); Assert.AreEqual(y2Expected, intersectionCoordinates[1].Y, Tolerance); }
/// <summary> /// The curves intersect. /// </summary> /// <param name="curve1">The first curve.</param> /// <param name="curve2">The first curve.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool AreIntersecting(CircularCurve curve1, CircularCurve curve2) { throw new NotImplementedException(); }
/// <summary> /// Determines if the curves are tangent to each other. /// </summary> /// <param name="curve1">The curve1.</param> /// <param name="curve2">The curve2.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> /// <exception cref="NotImplementedException"></exception> public static bool AreTangent(CircularCurve curve1, CircularCurve curve2) { throw new NotImplementedException(); }
/// <summary> /// The separation of the centers of the curves. /// </summary> /// <param name="curve1">The curve1.</param> /// <param name="curve2">The curve2.</param> /// <returns>System.Double.</returns> public static double CenterSeparations(CircularCurve curve1, CircularCurve curve2) { throw new NotImplementedException(); }
/// <summary> /// The coordinate(s) of the intersection(s) of two curves. /// </summary> /// <param name="curve1">The first curve.</param> /// <param name="curve2">The first curve.</param> /// <returns>CartesianCoordinate[].</returns> public static CartesianCoordinate[] IntersectionCoordinates(CircularCurve curve1, CircularCurve curve2) { throw new NotImplementedException(); }
/// <summary> /// Draws a circular curve geometry shape. /// </summary> /// <param name="circularCurve">Circular curve geometry shape.</param> private void DrawCircularCurve(CircularCurve circularCurve) { if ((circularCurve.Start.X == circularCurve.Middle.X && circularCurve.Start.X == circularCurve.End.X) || (circularCurve.Start.Y == circularCurve.Middle.Y && circularCurve.Start.Y == circularCurve.End.Y)) { DrawLine(new StraightLine(circularCurve.Start, circularCurve.End)); } Point a = circularCurve.Start; Point b = circularCurve.Middle; Point c = circularCurve.End; ILine p1 = CreatePerpendicularLineInBox(new StraightLine(a, b)); ILine p2 = CreatePerpendicularLineInBox(new StraightLine(b, c)); Point intersection = FindIntersection(p1, p2); double radius = Math.Sqrt(Math.Pow(intersection.X - a.X, 2) + Math.Pow(intersection.Y - a.Y, 2)); double a_angle = GetAngle(intersection, a); double b_angle = GetAngle(intersection, b); double c_angle = GetAngle(intersection, c); double startAngle = 0, sweepAngle = 0; if (a_angle < b_angle && b_angle < c_angle) { startAngle = a_angle; sweepAngle = c_angle - a_angle; } else if (a_angle < c_angle && c_angle < b_angle) { startAngle = 0; sweepAngle = 360; } else if (b_angle < a_angle && a_angle < c_angle) { startAngle = c_angle; sweepAngle = 360 - c_angle + a_angle; } else if (b_angle < c_angle && c_angle < a_angle) { startAngle = a_angle; sweepAngle = 360 - a_angle + c_angle; } else if (c_angle < a_angle && a_angle < b_angle) { startAngle = a_angle; sweepAngle = 360 - a_angle + c_angle; } else if (c_angle < b_angle && b_angle < c_angle) { startAngle = 0; sweepAngle = 360; } double box_x = intersection.X - radius; double box_y = intersection.Y + radius; double width = radius * 2; double height = width; graphics.DrawArc( pen: drawingPen, x: (float)box_x, y: canvasHeight - (float)box_y, width: (float)width, height: (float)height, startAngle: (float)startAngle, sweepAngle: (float)sweepAngle); }