From 8e58ac52086db8eedb3d929ddc9b6aa885b67f3f Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 5 Sep 2011 17:18:57 -0400 Subject: [PATCH] Add the 'dot' function for Points. --- src/Point.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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, -- 2.43.2