5 import qualified Face (Face(Face, v0, v1, v2, v3))
8 import Tetrahedron hiding (c)
9 import ThreeDimensional
11 data Cube = Cube { h :: Double,
15 fv :: FunctionValues }
19 instance Show Cube where
21 "Cube_" ++ subscript ++ "\n" ++
22 " h: " ++ (show (h c)) ++ "\n" ++
23 " Center: " ++ (show (center c)) ++ "\n" ++
24 " xmin: " ++ (show (xmin c)) ++ "\n" ++
25 " xmax: " ++ (show (xmax c)) ++ "\n" ++
26 " ymin: " ++ (show (ymin c)) ++ "\n" ++
27 " ymax: " ++ (show (ymax c)) ++ "\n" ++
28 " zmin: " ++ (show (zmin c)) ++ "\n" ++
29 " zmax: " ++ (show (zmax c)) ++ "\n" ++
30 " fv: " ++ (show (Cube.fv c)) ++ "\n"
33 (show (i c)) ++ "," ++ (show (j c)) ++ "," ++ (show (k c))
37 empty_cube = Cube 0 0 0 0 empty_values
40 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
42 xmin :: Cube -> Double
43 xmin c = (2*i' - 1)*delta / 2
45 i' = fromIntegral (i c) :: Double
48 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
50 xmax :: Cube -> Double
51 xmax c = (2*i' + 1)*delta / 2
53 i' = fromIntegral (i c) :: Double
56 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
58 ymin :: Cube -> Double
59 ymin c = (2*j' - 1)*delta / 2
61 j' = fromIntegral (j c) :: Double
64 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
66 ymax :: Cube -> Double
67 ymax c = (2*j' + 1)*delta / 2
69 j' = fromIntegral (j c) :: Double
72 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
74 zmin :: Cube -> Double
75 zmin c = (2*k' - 1)*delta / 2
77 k' = fromIntegral (k c) :: Double
80 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
82 zmax :: Cube -> Double
83 zmax c = (2*k' + 1)*delta / 2
85 k' = fromIntegral (k c) :: Double
88 instance ThreeDimensional Cube where
89 -- | The center of Cube_ijk coincides with v_ijk at
90 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
94 i' = fromIntegral (i c) :: Double
95 j' = fromIntegral (j c) :: Double
96 k' = fromIntegral (k c) :: Double
102 | (x_coord p) < (xmin c) = False
103 | (x_coord p) > (xmax c) = False
104 | (y_coord p) < (ymin c) = False
105 | (y_coord p) > (ymax c) = False
106 | (z_coord p) < (zmin c) = False
107 | (z_coord p) > (zmax c) = False
114 -- | The top (in the direction of z) face of the cube.
115 top_face :: Cube -> Face.Face
116 top_face c = Face.Face v0' v1' v2' v3'
119 v0' = (center c) + (delta, -delta, delta)
120 v1' = (center c) + (delta, delta, delta)
121 v2' = (center c) + (-delta, delta, delta)
122 v3' = (center c) + (-delta, -delta, delta)
126 -- | The back (in the direction of x) face of the cube.
127 back_face :: Cube -> Face.Face
128 back_face c = Face.Face v0' v1' v2' v3'
131 v0' = (center c) + (delta, delta, delta)
132 v1' = (center c) + (delta, delta, -delta)
133 v2' = (center c) + (delta, -delta, -delta)
134 v3' = (center c) + (delta, -delta, delta)
137 -- The bottom face (in the direction of -z) of the cube.
138 down_face :: Cube -> Face.Face
139 down_face c = Face.Face v0' v1' v2' v3'
142 v0' = (center c) + (delta, delta, -delta)
143 v1' = (center c) + (-delta, delta, -delta)
144 v2' = (center c) + (-delta, -delta, -delta)
145 v3' = (center c) + (delta, -delta, -delta)
149 -- | The front (in the direction of -x) face of the cube.
150 front_face :: Cube -> Face.Face
151 front_face c = Face.Face v0' v1' v2' v3'
154 v0' = (center c) + (-delta, -delta, delta)
155 v1' = (center c) + (-delta, delta, delta)
156 v2' = (center c) + (-delta, delta, -delta)
157 v3' = (center c) + (-delta, -delta, -delta)
159 -- | The left (in the direction of -y) face of the cube.
160 left_face :: Cube -> Face.Face
161 left_face c = Face.Face v0' v1' v2' v3'
164 v0' = (center c) + (-delta, -delta, delta)
165 v1' = (center c) + (delta, -delta, delta)
166 v2' = (center c) + (delta, -delta, -delta)
167 v3' = (center c) + (-delta, -delta, -delta)
170 -- | The right (in the direction of y) face of the cube.
171 right_face :: Cube -> Face.Face
172 right_face c = Face.Face v0' v1' v2' v3'
175 v0' = (center c) + (-delta, delta, -delta)
176 v1' = (center c) + (delta, delta, -delta)
177 v2' = (center c) + (delta, delta, delta)
178 v3' = (center c) + (-delta, delta, delta)
181 reorient :: Tetrahedron -> Tetrahedron
183 -- | volume t > 0 = t
184 -- | otherwise = t { v2 = (v3 t),
187 tetrahedron0 :: Cube -> Tetrahedron
189 reorient $ Tetrahedron (Cube.fv c) v0' v1' v2' v3'
192 v1' = center (front_face c)
193 v2' = Face.v0 (front_face c)
194 v3' = Face.v1 (front_face c)
196 tetrahedron1 :: Cube -> Tetrahedron
198 reorient $ Tetrahedron fv' v0' v1' v2' v3'
201 v1' = center (front_face c)
202 v2' = Face.v1 (front_face c)
203 v3' = Face.v2 (front_face c)
204 fv' = rotate (Cube.fv c) ccwx
206 tetrahedron2 :: Cube -> Tetrahedron
208 reorient $ Tetrahedron fv' v0' v1' v2' v3'
211 v1' = center (front_face c)
212 v2' = Face.v2 (front_face c)
213 v3' = Face.v3 (front_face c)
214 fv' = rotate (Cube.fv c) (ccwx . ccwx)
216 tetrahedron3 :: Cube -> Tetrahedron
218 reorient $ Tetrahedron fv' v0' v1' v2' v3'
221 v1' = center (front_face c)
222 v2' = Face.v3 (front_face c)
223 v3' = Face.v0 (front_face c)
224 fv' = rotate (Cube.fv c) cwx
226 tetrahedron4 :: Cube -> Tetrahedron
228 reorient $ Tetrahedron fv' v0' v1' v2' v3'
231 v1' = center (top_face c)
232 v2' = Face.v0 (top_face c)
233 v3' = Face.v1 (top_face c)
234 fv' = rotate (Cube.fv c) cwy
236 tetrahedron5 :: Cube -> Tetrahedron
238 reorient $ Tetrahedron fv' v0' v1' v2' v3'
241 v1' = center (top_face c)
242 v2' = Face.v1 (top_face c)
243 v3' = Face.v2 (top_face c)
244 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) ccwx
246 tetrahedron6 :: Cube -> Tetrahedron
248 reorient $ Tetrahedron fv' v0' v1' v2' v3'
251 v1' = center (top_face c)
252 v2' = Face.v2 (top_face c)
253 v3' = Face.v3 (top_face c)
254 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) (ccwx . ccwx)
256 tetrahedron7 :: Cube -> Tetrahedron
258 reorient $ Tetrahedron fv' v0' v1' v2' v3'
261 v1' = center (top_face c)
262 v2' = Face.v3 (top_face c)
263 v3' = Face.v0 (top_face c)
264 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) cwx
266 tetrahedrons :: Cube -> [Tetrahedron]