+//
+// N.B.: l is the line, c is the circle
+//
+void Geometry::CheckLineToCircleIntersection(Object * l, Object * c)
+{
+ // Set up global vars
+ Global::numIntersectPoints = Global::numIntersectParams = 0;
+
+ // Step 1: Find shortest distance from center of circle to the infinite line
+ double t = ParameterOfLineAndPoint(l->p[0], l->p[1], c->p[0]);
+ Point p = l->p[0] + (Vector(l->p[0], l->p[1]) * t);
+ Vector radial = Vector(c->p[0], p);
+ double distance = radial.Magnitude();
+
+ // Step 2: See if we have 0, 1, or 2 intersection points
+
+ // Case #1: No intersection points
+ if (distance > c->radius[0])
+ return;
+ // Case #2: One intersection point (possibly--tangent)
+ else if (distance == c->radius[0])
+ {
+ // Only intersects if the parameter is on the line segment!
+ if ((t >= 0.0) && (t <= 1.0))
+ {
+ Global::intersectPoint[0] = c->p[0] + radial;
+ Global::numIntersectPoints = 1;
+ }
+
+ return;
+ }
+
+ // Case #3: Two intersection points (possibly--secant)
+
+ // So, we have the line, and the perpendicular from the center of the
+ // circle to the line. Now figure out where the intersection points are.
+ // This is a right triangle, though do we really know all the sides?
+ // Don't need to, 2 is enough for Pythagoras :-)
+ // Radius is the hypotenuse, so we have to use c² = a² + b² => a² = c² - b²
+ double perpendicularLength = sqrt((c->radius[0] * c->radius[0]) - (distance * distance));
+
+ // Now, find the intersection points using the length...
+ Vector lineUnit = Vector(l->p[0], l->p[1]).Unit();
+ Point i1 = p + (lineUnit * perpendicularLength);
+ Point i2 = p - (lineUnit * perpendicularLength);
+
+ // Next we need to see if they are on the line segment...
+ double u = ParameterOfLineAndPoint(l->p[0], l->p[1], i1);
+ double v = ParameterOfLineAndPoint(l->p[0], l->p[1], i2);
+
+ if ((u >= 0.0) && (u <= 1.0))
+ {
+ Global::intersectPoint[Global::numIntersectPoints] = i1;
+ Global::numIntersectPoints++;
+ }
+
+ if ((v >= 0.0) && (v <= 1.0))
+ {
+ Global::intersectPoint[Global::numIntersectPoints] = i2;
+ Global::numIntersectPoints++;
+ }
+}
+
+// should we just do common trig solves, like AAS, ASA, SAS, SSA?
+// Law of Cosines:
+// c² = a² + b² - 2ab * cos(C)
+// Solving for C:
+// cos(C) = (c² - a² - b²) / -2ab = (a² + b² - c²) / 2ab
+// Law of Sines:
+// a / sin A = b / sin B = c / sin C
+
+// Solve the angles of the triangle given the sides. Angles returned are
+// opposite of the given sides (so a1 consists of sides s2 & s3, and so on).
+void Geometry::FindAnglesForSides(double s1, double s2, double s3, double * a1, double * a2, double * a3)
+{
+ // Use law of cosines to find 1st angle
+ double cosine1 = ((s2 * s2) + (s3 * s3) - (s1 * s1)) / (2.0 * s2 * s3);