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))
36 -- | Returns an empty 'Cube'.
38 empty_cube = Cube 0 0 0 0 empty_values
41 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
43 xmin :: Cube -> Double
44 xmin c = (2*i' - 1)*delta / 2
46 i' = fromIntegral (i c) :: Double
49 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
51 xmax :: Cube -> Double
52 xmax c = (2*i' + 1)*delta / 2
54 i' = fromIntegral (i c) :: Double
57 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
59 ymin :: Cube -> Double
60 ymin c = (2*j' - 1)*delta / 2
62 j' = fromIntegral (j c) :: Double
65 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
67 ymax :: Cube -> Double
68 ymax c = (2*j' + 1)*delta / 2
70 j' = fromIntegral (j c) :: Double
73 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
75 zmin :: Cube -> Double
76 zmin c = (2*k' - 1)*delta / 2
78 k' = fromIntegral (k c) :: Double
81 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
83 zmax :: Cube -> Double
84 zmax c = (2*k' + 1)*delta / 2
86 k' = fromIntegral (k c) :: Double
89 instance ThreeDimensional Cube where
90 -- | The center of Cube_ijk coincides with v_ijk at
91 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
95 i' = fromIntegral (i c) :: Double
96 j' = fromIntegral (j c) :: Double
97 k' = fromIntegral (k c) :: Double
102 -- | It's easy to tell if a point is within a cube; just make sure
103 -- that it falls on the proper side of each of the cube's faces.
105 | (x_coord p) < (xmin c) = False
106 | (x_coord p) > (xmax c) = False
107 | (y_coord p) < (ymin c) = False
108 | (y_coord p) > (ymax c) = False
109 | (z_coord p) < (zmin c) = False
110 | (z_coord p) > (zmax c) = False
117 -- | The top (in the direction of z) face of the cube.
118 top_face :: Cube -> Face.Face
119 top_face c = Face.Face v0' v1' v2' v3'
122 v0' = (center c) + (delta, -delta, delta)
123 v1' = (center c) + (delta, delta, delta)
124 v2' = (center c) + (-delta, delta, delta)
125 v3' = (center c) + (-delta, -delta, delta)
129 -- | The back (in the direction of x) face of the cube.
130 back_face :: Cube -> Face.Face
131 back_face c = Face.Face v0' v1' v2' v3'
134 v0' = (center c) + (delta, -delta, -delta)
135 v1' = (center c) + (delta, delta, -delta)
136 v2' = (center c) + (delta, delta, delta)
137 v3' = (center c) + (delta, -delta, delta)
140 -- The bottom face (in the direction of -z) of the cube.
141 down_face :: Cube -> Face.Face
142 down_face c = Face.Face v0' v1' v2' v3'
145 v0' = (center c) + (-delta, -delta, -delta)
146 v1' = (center c) + (-delta, delta, -delta)
147 v2' = (center c) + (delta, delta, -delta)
148 v3' = (center c) + (delta, -delta, -delta)
152 -- | The front (in the direction of -x) face of the cube.
153 front_face :: Cube -> Face.Face
154 front_face c = Face.Face v0' v1' v2' v3'
157 v0' = (center c) + (-delta, -delta, delta)
158 v1' = (center c) + (-delta, delta, delta)
159 v2' = (center c) + (-delta, delta, -delta)
160 v3' = (center c) + (-delta, -delta, -delta)
162 -- | The left (in the direction of -y) face of the cube.
163 left_face :: Cube -> Face.Face
164 left_face c = Face.Face v0' v1' v2' v3'
167 v0' = (center c) + (delta, -delta, delta)
168 v1' = (center c) + (-delta, -delta, delta)
169 v2' = (center c) + (-delta, -delta, -delta)
170 v3' = (center c) + (delta, -delta, -delta)
173 -- | The right (in the direction of y) face of the cube.
174 right_face :: Cube -> Face.Face
175 right_face c = Face.Face v0' v1' v2' v3'
178 v0' = (center c) + (-delta, delta, delta)
179 v1' = (center c) + (delta, delta, delta)
180 v2' = (center c) + (delta, delta, -delta)
181 v3' = (center c) + (-delta, delta, -delta)
184 tetrahedron0 :: Cube -> Tetrahedron
186 Tetrahedron (Cube.fv c) v0' v1' v2' v3'
189 v1' = center (front_face c)
190 v2' = Face.v0 (front_face c)
191 v3' = Face.v1 (front_face c)
193 tetrahedron1 :: Cube -> Tetrahedron
195 Tetrahedron fv' v0' v1' v2' v3'
198 v1' = center (front_face c)
199 v2' = Face.v1 (front_face c)
200 v3' = Face.v2 (front_face c)
201 fv' = rotate (Cube.fv c) cwx
203 tetrahedron2 :: Cube -> Tetrahedron
205 Tetrahedron fv' v0' v1' v2' v3'
208 v1' = center (front_face c)
209 v2' = Face.v2 (front_face c)
210 v3' = Face.v3 (front_face c)
211 fv' = rotate (Cube.fv c) (cwx . cwx)
213 tetrahedron3 :: Cube -> Tetrahedron
215 Tetrahedron fv' v0' v1' v2' v3'
218 v1' = center (front_face c)
219 v2' = Face.v3 (front_face c)
220 v3' = Face.v0 (front_face c)
221 fv' = rotate (Cube.fv c) ccwx
223 tetrahedron4 :: Cube -> Tetrahedron
225 Tetrahedron fv' v0' v1' v2' v3'
228 v1' = center (top_face c)
229 v2' = Face.v0 (top_face c)
230 v3' = Face.v1 (top_face c)
231 fv' = rotate (Cube.fv c) ccwy
233 tetrahedron5 :: Cube -> Tetrahedron
235 Tetrahedron fv' v0' v1' v2' v3'
238 v1' = center (top_face c)
239 v2' = Face.v1 (top_face c)
240 v3' = Face.v2 (top_face c)
241 fv' = rotate (Tetrahedron.fv (tetrahedron4 c)) cwz
243 tetrahedron6 :: Cube -> Tetrahedron
245 Tetrahedron fv' v0' v1' v2' v3'
248 v1' = center (top_face c)
249 v2' = Face.v2 (top_face c)
250 v3' = Face.v3 (top_face c)
251 fv' = rotate (Tetrahedron.fv (tetrahedron4 c)) (cwz . cwz)
253 tetrahedron7 :: Cube -> Tetrahedron
255 Tetrahedron fv' v0' v1' v2' v3'
258 v1' = center (top_face c)
259 v2' = Face.v3 (top_face c)
260 v3' = Face.v0 (top_face c)
261 fv' = rotate (Tetrahedron.fv (tetrahedron4 c)) ccwz
263 tetrahedron8 :: Cube -> Tetrahedron
265 Tetrahedron fv' v0' v1' v2' v3'
268 v1' = center (back_face c)
269 v2' = Face.v0 (back_face c)
270 v3' = Face.v1 (back_face c)
271 fv' = rotate (Tetrahedron.fv (tetrahedron4 c)) ccwy
273 tetrahedron9 :: Cube -> Tetrahedron
275 Tetrahedron fv' v0' v1' v2' v3'
278 v1' = center (back_face c)
279 v2' = Face.v1 (back_face c)
280 v3' = Face.v2 (back_face c)
281 fv' = rotate (Tetrahedron.fv (tetrahedron8 c)) cwx
283 tetrahedron10 :: Cube -> Tetrahedron
285 Tetrahedron fv' v0' v1' v2' v3'
288 v1' = center (back_face c)
289 v2' = Face.v2 (back_face c)
290 v3' = Face.v3 (back_face c)
291 fv' = rotate (Tetrahedron.fv (tetrahedron8 c)) (cwx . cwx)
294 tetrahedron11 :: Cube -> Tetrahedron
296 Tetrahedron fv' v0' v1' v2' v3'
299 v1' = center (back_face c)
300 v2' = Face.v3 (back_face c)
301 v3' = Face.v0 (back_face c)
302 fv' = rotate (Tetrahedron.fv (tetrahedron8 c)) ccwx
305 tetrahedron12 :: Cube -> Tetrahedron
307 Tetrahedron fv' v0' v1' v2' v3'
310 v1' = center (down_face c)
311 v2' = Face.v0 (down_face c)
312 v3' = Face.v1 (down_face c)
313 fv' = rotate (Tetrahedron.fv (tetrahedron8 c)) ccwy
316 tetrahedron13 :: Cube -> Tetrahedron
318 Tetrahedron fv' v0' v1' v2' v3'
321 v1' = center (down_face c)
322 v2' = Face.v1 (down_face c)
323 v3' = Face.v2 (down_face c)
324 fv' = rotate (Tetrahedron.fv (tetrahedron12 c)) cwz
327 tetrahedron14 :: Cube -> Tetrahedron
329 Tetrahedron fv' v0' v1' v2' v3'
332 v1' = center (down_face c)
333 v2' = Face.v2 (down_face c)
334 v3' = Face.v3 (down_face c)
335 fv' = rotate (Tetrahedron.fv (tetrahedron13 c)) (cwz . cwz)
338 tetrahedron15 :: Cube -> Tetrahedron
340 Tetrahedron fv' v0' v1' v2' v3'
343 v1' = center (down_face c)
344 v2' = Face.v3 (down_face c)
345 v3' = Face.v0 (down_face c)
346 fv' = rotate (Tetrahedron.fv (tetrahedron12 c)) ccwz
349 tetrahedron16 :: Cube -> Tetrahedron
351 Tetrahedron fv' v0' v1' v2' v3'
354 v1' = center (right_face c)
355 v2' = Face.v0 (right_face c)
356 v3' = Face.v1 (right_face c)
357 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) cwz
360 tetrahedron17 :: Cube -> Tetrahedron
362 Tetrahedron fv' v0' v1' v2' v3'
365 v1' = center (right_face c)
366 v2' = Face.v1 (right_face c)
367 v3' = Face.v2 (right_face c)
368 fv' = rotate (Tetrahedron.fv (tetrahedron16 c)) cwy
371 tetrahedron18 :: Cube -> Tetrahedron
373 Tetrahedron fv' v0' v1' v2' v3'
376 v1' = center (right_face c)
377 v2' = Face.v2 (right_face c)
378 v3' = Face.v3 (right_face c)
379 fv' = rotate (Tetrahedron.fv (tetrahedron16 c)) (cwy . cwy)
382 tetrahedron19 :: Cube -> Tetrahedron
384 Tetrahedron fv' v0' v1' v2' v3'
387 v1' = center (right_face c)
388 v2' = Face.v3 (right_face c)
389 v3' = Face.v0 (right_face c)
390 fv' = rotate (Tetrahedron.fv (tetrahedron16 c)) ccwy
393 tetrahedron20 :: Cube -> Tetrahedron
395 Tetrahedron fv' v0' v1' v2' v3'
398 v1' = center (left_face c)
399 v2' = Face.v0 (left_face c)
400 v3' = Face.v1 (left_face c)
401 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) ccwz
404 tetrahedron21 :: Cube -> Tetrahedron
406 Tetrahedron fv' v0' v1' v2' v3'
409 v1' = center (left_face c)
410 v2' = Face.v1 (left_face c)
411 v3' = Face.v2 (left_face c)
412 fv' = rotate (Tetrahedron.fv (tetrahedron20 c)) cwy
415 tetrahedron22 :: Cube -> Tetrahedron
417 Tetrahedron fv' v0' v1' v2' v3'
420 v1' = center (left_face c)
421 v2' = Face.v2 (left_face c)
422 v3' = Face.v3 (left_face c)
423 fv' = rotate (Tetrahedron.fv (tetrahedron20 c)) (cwy . cwy)
426 tetrahedron23 :: Cube -> Tetrahedron
428 Tetrahedron fv' v0' v1' v2' v3'
431 v1' = center (left_face c)
432 v2' = Face.v3 (left_face c)
433 v3' = Face.v0 (left_face c)
434 fv' = rotate (Tetrahedron.fv (tetrahedron20 c)) ccwy
437 tetrahedrons :: Cube -> [Tetrahedron]