-double Vector::Parameter(Vector v1, Vector v2, Vector p)
-{
- // Geometric interpretation:
- // The parameterized point on the vector lineSegment is where the normal of
- // the lineSegment to the point intersects lineSegment. If the pp < 0, then
- // the perpendicular lies beyond the 1st endpoint. If pp > 1, then the
- // perpendicular lies beyond the 2nd endpoint.
-
- Vector lineSegment = v2 - v1;
- double magnitude = lineSegment.Magnitude();
- Vector pointSegment = p - v1;
- double t = lineSegment.Dot(pointSegment) / (magnitude * magnitude);
- return t;
-}
+ // Find the intersection of the line and position + normal to the line
+ double px = (((p1.x * p2.y) - (p1.y * p2.x)) * (position.x - p4.x))
+ - ((p1.x - p2.x) * ((position.x * p4.y) - (position.y * p4.x)));
+ double py = (((p1.x * p2.y) - (p1.y * p2.x)) * (position.y - p4.y))
+ - ((p1.y - p2.y) * ((position.x * p4.y) - (position.y * p4.x)));
+ double d = ((p1.x - p2.x) * (position.y - p4.y))
+ - ((p1.y - p2.y) * (position.x - p4.x));