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 p1 + p2 = (x1+x2, y1+y2, z1+z2)
30 p1 - p2 = (x1-x2, y1-y2, z1-z2)
39 p1 * p2 = (x1*x2, y1*y2, z1*z2)
48 abs (x, y, z) = (abs x, abs y, abs z)
49 signum (x, y, z) = (signum x, signum y, signum z)
50 fromInteger n = (fromInteger n, fromInteger n, fromInteger n)
53 scale :: Point -> Double -> Point
54 scale (x, y, z) d = (x*d, y*d, z*d)
57 distance :: Point -> Point -> Double
59 sqrt $ (x2 - x1)^(2::Int) + (y2 - y1)^(2::Int) + (z2 - z1)^(2::Int)
69 is_close :: Point -> Point -> Bool
70 is_close p1 p2 = (distance p1 p2) ~= 0