+ {
+// WHY would you do this??? The lines overlap at an INFINITE number of points!
+// The assumption is that the angle is 180°, not 0°.
+ // If we want to detect the degenerate case, we can check the parameter of the endpoints of the one line to the other. If any of the parameters are in (0, 1), then it's the degenerate case (we would check the endpoints of the shorter segment against the longer).
+/* double qpxr = (v1.x * r.y) - (r.x * v1.y);
+
+ // Line segments are parallel, so no intersection...
+ if (qpxr != 0)
+ return;
+
+ // Otherwise, the segments are colinear. Need to check for the 0° (degenerate) vs the 180° (OK) case.
+ Object * larger = l1;
+ Object * smaller = l2;
+
+ if (r->Magnitude() < s->Magnitude())
+ {
+ larger = l2;
+ smaller = l1;
+ }
+
+ double param1 = ParameterOfLineAndPoint(larger->p[0], larger->p[1], smaller->p[0]);
+ double param2 = ParameterOfLineAndPoint(larger->p[0], larger->p[1], smaller->p[1]);
+
+ // Check for the degenerate case, and return if found
+ if ((param1 > 0 && param1 < 1.0) || (param2 > 0 && param2 < 1.0))
+ return;
+
+//// or just use AngleBetween: Nah, won't work...
+
+ // Check to see which endpoints are connected... Four possibilities:
+ if (l1->p[0] == l2->p[0])
+ t = 0, u = 0;
+ else if (l1->p[0] == l2->p[1])
+ t = 0, u = 1.0;
+ else if (l1->p[1] == l2->p[0])
+ t = 1.0, u = 0;
+ else if (l1->p[1] == l2->p[1])
+ t = 1.0, u = 1.0;
+ else*/
+ return;
+ }
+ else
+ {
+ t = ((v1.x * s.y) - (s.x * v1.y)) / rxs;
+ u = ((v1.x * r.y) - (r.x * v1.y)) / rxs;
+ }
+
+ // Check that the parameters are above the epsilon, otherwise clamp them to
+ // zero or one, as the case may be
+ if (fabs(t) < EPSILON)
+ t = 0;
+ else if (fabs(1.0 - t) < EPSILON)
+ t = 1.0;
+
+ if (fabs(u) < EPSILON)
+ u = 0;
+ else if (fabs(1.0 - u) < EPSILON)
+ u = 1.0;
+
+ Global::intersectParam[0] = t;
+ Global::intersectParam[1] = u;
+
+ // If the parameters are in range, we have overlap!
+ if ((t >= 0) && (t <= 1.0) && (u >= 0) && (u <= 1.0))
+ Global::numIntersectParams = 2;
+}
+
+void Geometry::CheckCircleToCircleIntersection(Object * c1, Object * c2)
+{
+ // Set up global vars
+ Global::numIntersectPoints = Global::numIntersectParams = 0;
+
+ // Get the distance between the centers of the circles
+ Vector centerLine(c1->p[0], c2->p[0]);
+ double d = centerLine.Magnitude();
+ double clAngle = centerLine.Angle();
+
+ // If the distance between centers is greater than the sum of the radii or
+ // less than the difference between the radii, there is NO intersection
+ if ((d > (c1->radius[0] + c2->radius[0]))
+ || (d < fabs(c1->radius[0] - c2->radius[0])))
+ return;
+
+ // If the distance between centers is equal to the sum of the radii or
+ // equal to the difference between the radii, the intersection is tangent
+ // to both circles.
+ if (d == (c1->radius[0] + c2->radius[0]))
+ {
+ Global::intersectPoint[0].x = c1->p[0].x + (cos(clAngle) * c1->radius[0]);
+ Global::intersectPoint[0].y = c1->p[0].y + (sin(clAngle) * c1->radius[0]);
+ Global::numIntersectPoints = 1;
+ return;
+ }
+ else if (d == fabs(c1->radius[0] - c2->radius[0]))
+ {
+ double sign = (c1->radius[0] > c2->radius[0] ? +1 : -1);
+ Global::intersectPoint[0].x = c1->p[0].x + (cos(clAngle) * c1->radius[0] * sign);
+ Global::intersectPoint[0].y = c1->p[0].y + (sin(clAngle) * c1->radius[0] * sign);
+ Global::numIntersectPoints = 1;
+ return;
+ }