X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FFace.hs;h=bc316a72cee9ae4eb815424b2ccbfe8705316911;hb=6985f184b560c21139209e5cc9fd0eaf4a51715c;hp=d93ebffba1457f873d7296f9f29cfd534dfcc749;hpb=89b8b6e94fcc944a1f4611811265f3c6217af850;p=spline3.git diff --git a/src/Face.hs b/src/Face.hs index d93ebff..bc316a7 100644 --- a/src/Face.hs +++ b/src/Face.hs @@ -1,160 +1,35 @@ +-- | The Face module just contains the definition of the 'Face' data +-- type and its two typeclass instances. module Face + ( Face(..) ) where -import Cube -import Grid import Point -import Tetrahedron hiding (c, cube, v0, v1, v2, v3) import ThreeDimensional -data Face = Face { cube :: Cube, - v0 :: Point, - v1 :: Point, - v2 :: Point, - v3 :: Point } +data Face = Face { v0 :: !Point, + v1 :: !Point, + v2 :: !Point, + v3 :: !Point } deriving (Eq) instance Show Face where - show f = "Face (Cube_" ++ (show i') ++ "," ++ (show j') ++ "," ++ - (show k') ++ ") " ++ "(v0: " ++ (show (v0 f)) ++ ") (v1: " ++ - (show (v1 f)) ++ ") (v2: " ++ (show (v2 f)) ++ ") (v3: " ++ - (show (v3 f)) ++ ")\n\n" - where - i' = i (cube f) - j' = j (cube f) - k' = k (cube f) - + show f = "Face:\n" ++ + " v0: " ++ (show (v0 f)) ++ "\n" ++ + " v1: " ++ (show (v1 f)) ++ "\n" ++ + " v2: " ++ (show (v2 f)) ++ "\n" ++ + " v3: " ++ (show (v3 f)) ++ "\n" + +-- | The 'Face' type is an instance of 'ThreeDimensional' so that we +-- can call the 'center' function on it. This is useful because the +-- center of a face is always a vertex of a tetrahedron. instance ThreeDimensional Face where + -- | Since a face is square, we can just average the four vertices + -- to find the center. center f = ((v0 f) + (v1 f) + (v2 f) + (v3 f)) `scale` (1/4) - -- Too lazy to implement this right now. - contains_point _ _ = False - --- The top face of the cube. -face0 :: Cube -> Face -face0 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (-delta, delta, delta) - v1' = (center c) + (delta, delta, delta) - v2' = (center c) + (delta, -delta, delta) - v3' = (center c) + (-delta, -delta, delta) - --- The right face of the cube. -face1 :: Cube -> Face -face1 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (delta, delta, delta) - v1' = (center c) + (delta, delta, -delta) - v2' = (center c) + (delta, -delta, -delta) - v3' = (center c) + (delta, -delta, delta) - - --- The bottom face of the cube. -face2 :: Cube -> Face -face2 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (delta, delta, -delta) - v1' = (center c) + (-delta, delta, -delta) - v2' = (center c) + (-delta, -delta, -delta) - v3' = (center c) + (delta, -delta, -delta) - - --- The left face of the cube. -face3 :: Cube -> Face -face3 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (-delta, delta, -delta) - v1' = (center c) + (-delta, delta, delta) - v2' = (center c) + (-delta, -delta, delta) - v3' = (center c) + (-delta, -delta, -delta) - - --- The front face of the cube. -face4 :: Cube -> Face -face4 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (-delta, -delta, delta) - v1' = (center c) + (delta, -delta, delta) - v2' = (center c) + (delta, -delta, -delta) - v3' = (center c) + (-delta, -delta, -delta) - --- The back face of the cube. -face5 :: Cube -> Face -face5 c = Face c v0' v1' v2' v3' - where - g = grid c - delta = (1/2)*(h g) - v0' = (center c) + (-delta, delta, -delta) - v1' = (center c) + (delta, delta, -delta) - v2' = (center c) + (delta, delta, delta) - v3' = (center c) + (-delta, delta, delta) - - -tetrahedron0 :: Face -> Tetrahedron -tetrahedron0 f = - Tetrahedron c v0' v1' v2' v3' - where - c = cube f - v0' = v0 f - v1' = v1 f - v2' = center f - v3' = center c - -tetrahedron1 :: Face -> Tetrahedron -tetrahedron1 f = - Tetrahedron c v0' v1' v2' v3' - where - c = cube f - v0' = v1 f - v1' = v2 f - v2' = center f - v3' = center c - - -tetrahedron2 :: Face -> Tetrahedron -tetrahedron2 f = - Tetrahedron c v0' v1' v2' v3' - where - c = cube f - v0' = v2 f - v1' = v3 f - v2' = center f - v3' = center c - - -tetrahedron3 :: Face -> Tetrahedron -tetrahedron3 f = - Tetrahedron c v0' v1' v2' v3' - where - c = cube f - v0' = v3 f - v1' = v0 f - v2' = center f - v3' = center c - -tetrahedrons :: Cube -> [Tetrahedron] -tetrahedrons c = - concat [ - [tetrahedron0 f0, tetrahedron1 f0, tetrahedron2 f0, tetrahedron3 f0], - [tetrahedron0 f1, tetrahedron1 f1, tetrahedron2 f1, tetrahedron3 f2], - [tetrahedron0 f2, tetrahedron1 f2, tetrahedron2 f2, tetrahedron3 f2], - [tetrahedron0 f3, tetrahedron1 f3, tetrahedron2 f3, tetrahedron3 f3], - [tetrahedron0 f4, tetrahedron1 f4, tetrahedron2 f4, tetrahedron3 f4], - [tetrahedron0 f5, tetrahedron1 f5, tetrahedron2 f5, tetrahedron3 f5] ] - where - f0 = face0 c - f1 = face1 c - f2 = face2 c - f3 = face3 c - f4 = face4 c - f5 = face5 c + -- | It's possible to implement this, but it hasn't been done + -- yet. A face will contain a point if the point lies in the same + -- plane as the vertices of the face, and if it falls on the + -- correct side of the four sides of the face. + contains_point _ _ = False