- double t = ParameterOfLineAndPoint(l->position, l->endpoint, c->position);
-//small problem here: it clamps the result to the line segment. NOT what we want
-//here! !!! FIX !!! [DONE]
- Vector p = l->GetPointAtParameter(t);
- double distance = Vector::Magnitude(c->position, p);
-
- // If the center of the circle is farther from the line than the radius, fail.
- if (distance > c->radius)
- return 0;
-
- // Now we have to check for intersection points.
- // Tangent case: (needs to return something)
- if ((distance == c->radius) && (t >= 0.0) && (t <= 1.0))
- return 1;
-
- // The line intersects the circle in two points (possibly). Use Pythagorus
- // to find them for testing.
- double offset = sqrt((c->radius * c->radius) - (distance * distance));
-//need to convert distance to paramter value... :-/
-//t = position on line / length of line segment, so if we divide the offset by length,
-//that should give us what we want.
- double length = Vector::Magnitude(l->position, l->endpoint);
- double t1 = t + (offset / length);
- double t2 = t - (offset / length);
-
-//need to find angles for the circle...
- Vector cp1 = l->position + (Vector(l->position, l->endpoint) * (length * t1));
- Vector cp2 = l->position + (Vector(l->position, l->endpoint) * (length * t2));
- double a1 = Vector(c->position, cp1).Angle();
- double a2 = Vector(c->position, cp2).Angle();
-
-//instead of this, return a # which is the # of intersections. [DONE]
- int intersections = 0;
-
- // Now check for if the parameters are in range
- if ((t1 >= 0) && (t1 <= 1.0))
- {
- intersections++;
- }