From: Michael Orlitzky Date: Mon, 5 Sep 2011 21:18:57 +0000 (-0400) Subject: Add the 'dot' function for Points. X-Git-Tag: 0.0.1~159 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=8e58ac52086db8eedb3d929ddc9b6aa885b67f3f;p=spline3.git Add the 'dot' function for Points. --- diff --git a/src/Point.hs b/src/Point.hs index e5260ae..95b3364 100644 --- a/src/Point.hs +++ b/src/Point.hs @@ -24,8 +24,14 @@ scale (x, y, z) d = (x*d, y*d, z*d) -- | Returns the distance between p1 and p2. distance :: Point -> Point -> Double -distance (x1, y1, z1) (x2, y2, z2) = - sqrt $ (x2 - x1)^(2::Int) + (y2 - y1)^(2::Int) + (z2 - z1)^(2::Int) +distance p1 p2 = + sqrt $ p1 `dot` p2 + + +-- | Returns the dot product of two points (taken as three-vectors). +dot :: Point -> Point -> Double +dot (x1, y1, z1) (x2, y2, z2) = + (x2 - x1)^(2::Int) + (y2 - y1)^(2::Int) + (z2 - z1)^(2::Int) -- | Returns 'True' if p1 is close to (within 'epsilon' of) p2,