X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvector.cpp;h=ac5a2058191e4f7e11d24218ba8085e93d7372d8;hb=4b37ccbdf263a4798e53a62e33d869a728ace283;hp=ab1433f9c6a5123e6ca6a8475cbe852210ecb933;hpb=11802354d1ddc5bc571d83d8fc9b600618cb4372;p=architektonas diff --git a/src/vector.cpp b/src/vector.cpp index ab1433f..ac5a205 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -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 // perpendicular lies beyond the 2nd endpoint. - Vector lineSegment = v2 - v1; + Vector lineSegment = v1 - v2; double magnitude = lineSegment.Magnitude(); - Vector pointSegment = p - v1; + Vector pointSegment = p - v2; double t = lineSegment.Dot(pointSegment) / (magnitude * magnitude); - return t; } + +// Return the normal to the linesegment formed by the passed in points. +// (Not sure which is head or tail, or which hand the normal lies) +/*static*/ Vector Vector::Normal(Vector v1, Vector v2) +{ + Vector v = (v1 - v2).Unit(); + return Vector(-v.y, v.x); +} +