+\r
+\r
+double Vector::Magnitude(Vector v1, Vector v2)\r
+{\r
+ double xx = v1.x - v2.x;\r
+ double yy = v1.y - v2.y;\r
+ double zz = v1.z - v2.z;\r
+ return sqrt(xx * xx + yy * yy + zz * zz);\r
+}\r
+\r
+\r
+// Returns the parameter of a point in space to this vector. If the parameter\r
+// is between 0 and 1, the normal of the vector to the point is on the vector.\r
+double Vector::Parameter(Vector v1, Vector v2, Vector p)\r
+{\r
+ // Geometric interpretation:\r
+ // The parameterized point on the vector lineSegment is where the normal of\r
+ // the lineSegment to the point intersects lineSegment. If the pp < 0, then\r
+ // the perpendicular lies beyond the 1st endpoint. If pp > 1, then the\r
+ // perpendicular lies beyond the 2nd endpoint.\r
+\r
+ Vector lineSegment = v2 - v1;\r
+ double magnitude = lineSegment.Magnitude();\r
+ Vector pointSegment = p - v1;\r
+ double t = lineSegment.Dot(pointSegment) / (magnitude * magnitude);\r
+\r
+ return t;\r
+}\r
+\r