]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Face.hs
96092609fc55f99cc86459ebf787f26594efff1f
[spline3.git] / src / Face.hs
1 -- | The Face module just contains the definition of the 'Face' data
2 -- type and its two typeclass instances.
3 module Face
4 ( Face(..) )
5 where
6
7 import Point
8 import ThreeDimensional
9
10 data Face = Face { v0 :: Point,
11 v1 :: Point,
12 v2 :: Point,
13 v3 :: Point }
14 deriving (Eq)
15
16 instance Show Face where
17 show f = "Face:\n" ++
18 " v0: " ++ (show (v0 f)) ++ "\n" ++
19 " v1: " ++ (show (v1 f)) ++ "\n" ++
20 " v2: " ++ (show (v2 f)) ++ "\n" ++
21 " v3: " ++ (show (v3 f)) ++ "\n"
22
23 -- | The 'Face' type is an instance of 'ThreeDimensional' so that we
24 -- can call the 'center' function on it. This is useful because the
25 -- center of a face is always a vertex of a tetrahedron.
26 instance ThreeDimensional Face where
27 -- | Since a face is square, we can just average the four vertices
28 -- to find the center.
29 center f = ((v0 f) + (v1 f) + (v2 f) + (v3 f)) `scale` (1/4)
30
31 -- | It's possible to implement this, but it hasn't been done
32 -- yet. A face will contain a point if the point lies in the same
33 -- plane as the vertices of the face, and if it falls on the
34 -- correct side of the four sides of the face.
35 contains_point _ _ = False