]> Shamusworld >> Repos - architektonas/blobdiff - src/vector.cpp
Added Geometry class for common geometric tools used everywhere.
[architektonas] / src / vector.cpp
index ab1433f9c6a5123e6ca6a8475cbe852210ecb933..ac5a2058191e4f7e11d24218ba8085e93d7372d8 100644 (file)
@@ -244,11 +244,19 @@ double Vector::Parameter(Vector v1, Vector v2, Vector p)
        // 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
+       Vector lineSegment = v1 - v2;\r
        double magnitude = lineSegment.Magnitude();\r
-       Vector pointSegment = p - v1;\r
+       Vector pointSegment = p - v2;\r
        double t = lineSegment.Dot(pointSegment) / (magnitude * magnitude);\r
-\r
        return t;\r
 }\r
 \r
+\r
+// Return the normal to the linesegment formed by the passed in points.\r
+// (Not sure which is head or tail, or which hand the normal lies)\r
+/*static*/ Vector Vector::Normal(Vector v1, Vector v2)\r
+{\r
+       Vector v = (v1 - v2).Unit();\r
+       return Vector(-v.y, v.x);\r
+}\r
+\r