1 {-# LANGUAGE TypeSynonymInstances #-}
9 type Point = (Double, Double, Double)
11 x_coord :: Point -> Double
14 y_coord :: Point -> Double
17 z_coord :: Point -> Double
20 instance Num Point where
21 (x1,y1,z1) + (x2,y2,z2) = (x1+x2, y1+y2, z1+z2)
22 (x1,y1,z1) - (x2,y2,z2) = (x1-x2, y1-y2, z1-z2)
23 (x1,y1,z1) * (x2,y2,z2) = (x1*x2, y1*y2, z1*z2)
24 abs (x, y, z) = (abs x, abs y, abs z)
25 signum (x, y, z) = (signum x, signum y, signum z)
26 fromInteger n = (fromInteger n, fromInteger n, fromInteger n)
29 -- | Scale a point by a constant.
30 scale :: Point -> Double -> Point
31 scale (x, y, z) d = (x*d, y*d, z*d)
34 -- | Returns the distance between p1 and p2.
35 distance :: Point -> Point -> Double
37 sqrt $ (x2 - x1)^(2::Int) + (y2 - y1)^(2::Int) + (z2 - z1)^(2::Int)
47 -- | Returns 'True' if p1 is close to (within 'epsilon' of) p2,
49 is_close :: Point -> Point -> Bool
50 is_close p1 p2 = (distance p1 p2) ~= 0