5 import Face (Face(Face, v0, v1, v2, v3))
8 import Tetrahedron (Tetrahedron(Tetrahedron), fv)
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"
32 (show (i c)) ++ "," ++ (show (j c)) ++ "," ++ (show (k c))
36 empty_cube = Cube 0 0 0 0 empty_values
39 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
41 xmin :: Cube -> Double
42 xmin c = (2*i' - 1)*delta / 2
44 i' = fromIntegral (i c) :: Double
47 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
49 xmax :: Cube -> Double
50 xmax c = (2*i' + 1)*delta / 2
52 i' = fromIntegral (i c) :: Double
55 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
57 ymin :: Cube -> Double
58 ymin c = (2*j' - 1)*delta / 2
60 j' = fromIntegral (j c) :: Double
63 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
65 ymax :: Cube -> Double
66 ymax c = (2*j' + 1)*delta / 2
68 j' = fromIntegral (j c) :: Double
71 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
73 zmin :: Cube -> Double
74 zmin c = (2*k' - 1)*delta / 2
76 k' = fromIntegral (k c) :: Double
79 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
81 zmax :: Cube -> Double
82 zmax c = (2*k' + 1)*delta / 2
84 k' = fromIntegral (k c) :: Double
87 instance ThreeDimensional Cube where
88 -- | The center of Cube_ijk coincides with v_ijk at
89 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
93 i' = fromIntegral (i c) :: Double
94 j' = fromIntegral (j c) :: Double
95 k' = fromIntegral (k c) :: Double
101 | (x_coord p) < (xmin c) = False
102 | (x_coord p) > (xmax c) = False
103 | (y_coord p) < (ymin c) = False
104 | (y_coord p) > (ymax c) = False
105 | (z_coord p) < (zmin c) = False
106 | (z_coord p) > (zmax c) = False
110 -- instance Num Cube where
111 -- (Cube g1 i1 j1 k1 d1) + (Cube _ i2 j2 k2 d2) =
112 -- Cube g1 (i1 + i2) (j1 + j2) (k1 + k2) (d1 + d2)
114 -- (Cube g1 i1 j1 k1 d1) - (Cube _ i2 j2 k2 d2) =
115 -- Cube g1 (i1 - i2) (j1 - j2) (k1 - k2) (d1 - d2)
117 -- (Cube g1 i1 j1 k1 d1) * (Cube _ i2 j2 k2 d2) =
118 -- Cube g1 (i1 * i2) (j1 * j2) (k1 * k2) (d1 * d2)
120 -- abs (Cube g1 i1 j1 k1 d1) =
121 -- Cube g1 (abs i1) (abs j1) (abs k1) (abs d1)
123 -- signum (Cube g1 i1 j1 k1 d1) =
124 -- Cube g1 (signum i1) (signum j1) (signum k1) (signum d1)
126 -- fromInteger x = empty_cube { datum = (fromIntegral x) }
128 -- instance Fractional Cube where
129 -- (Cube g1 i1 j1 k1 d1) / (Cube _ _ _ _ d2) =
130 -- Cube g1 i1 j1 k1 (d1 / d2)
132 -- recip (Cube g1 i1 j1 k1 d1) =
133 -- Cube g1 i1 j1 k1 (recip d1)
135 -- fromRational q = empty_cube { datum = fromRational q }
139 -- | Return the cube corresponding to the grid point i,j,k. The list
140 -- of cubes is stored as [z][y][x] but we'll be requesting it by
141 -- [x][y][z] so we flip the indices in the last line.
142 -- cube_at :: Grid -> Int -> Int -> Int -> Cube
143 -- cube_at g i' j' k'
144 -- | i' >= length (function_values g) = Cube g i' j' k' 0
145 -- | i' < 0 = Cube g i' j' k' 0
146 -- | j' >= length ((function_values g) !! i') = Cube g i' j' k' 0
147 -- | j' < 0 = Cube g i' j' k' 0
148 -- | k' >= length (((function_values g) !! i') !! j') = Cube g i' j' k' 0
149 -- | k' < 0 = Cube g i' j' k' 0
151 -- (((cubes g) !! k') !! j') !! i'
160 -- | The top (in the direction of z) face of the cube.
161 top_face :: Cube -> Face
162 top_face c = Face v0' v1' v2' v3'
165 v0' = (center c) + (delta, delta, delta)
166 v1' = (center c) + (delta, -delta, delta)
167 v2' = (center c) + (-delta, -delta, delta)
168 v3' = (center c) + (-delta, delta, delta)
172 -- | The back (in the direction of x) face of the cube.
173 back_face :: Cube -> Face
174 back_face c = Face v0' v1' v2' v3'
177 v0' = (center c) + (delta, delta, delta)
178 v1' = (center c) + (delta, delta, -delta)
179 v2' = (center c) + (delta, -delta, -delta)
180 v3' = (center c) + (delta, -delta, delta)
183 -- The bottom face (in the direction of -z) of the cube.
184 down_face :: Cube -> Face
185 down_face c = Face v0' v1' v2' v3'
188 v0' = (center c) + (delta, delta, -delta)
189 v1' = (center c) + (-delta, delta, -delta)
190 v2' = (center c) + (-delta, -delta, -delta)
191 v3' = (center c) + (delta, -delta, -delta)
195 -- | The front (in the direction of -x) face of the cube.
196 front_face :: Cube -> Face
197 front_face c = Face v0' v1' v2' v3'
200 v0' = (center c) + (-delta, -delta, delta)
201 v1' = (center c) + (-delta, delta, delta)
202 v2' = (center c) + (-delta, delta, -delta)
203 v3' = (center c) + (-delta, -delta, -delta)
206 -- | The left (in the direction of -y) face of the cube.
207 left_face :: Cube -> Face
208 left_face c = Face v0' v1' v2' v3'
211 v0' = (center c) + (-delta, -delta, delta)
212 v1' = (center c) + (delta, -delta, delta)
213 v2' = (center c) + (delta, -delta, -delta)
214 v3' = (center c) + (-delta, -delta, -delta)
217 -- | The right (in the direction of y) face of the cube.
218 right_face :: Cube -> Face
219 right_face c = Face v0' v1' v2' v3'
222 v0' = (center c) + (-delta, delta, -delta)
223 v1' = (center c) + (delta, delta, -delta)
224 v2' = (center c) + (delta, delta, delta)
225 v3' = (center c) + (-delta, delta, delta)
229 tetrahedron0 :: Cube -> Tetrahedron
231 Tetrahedron (Cube.fv c) v0' v1' v2' v3'
234 v1' = center (front_face c)
235 v2' = v0 (front_face c)
236 v3' = v1 (front_face c)
238 tetrahedron1 :: Cube -> Tetrahedron
240 Tetrahedron fv' v0' v1' v2' v3'
243 v1' = center (front_face c)
244 v2' = v1 (front_face c)
245 v3' = v2 (front_face c)
246 fv' = rotate (Cube.fv c) ccwx
248 tetrahedron2 :: Cube -> Tetrahedron
250 Tetrahedron fv' v0' v1' v2' v3'
253 v1' = center (front_face c)
254 v2' = v2 (front_face c)
255 v3' = v3 (front_face c)
256 fv' = rotate (Cube.fv c) (ccwx . ccwx)
258 tetrahedron3 :: Cube -> Tetrahedron
260 Tetrahedron fv' v0' v1' v2' v3'
263 v1' = center (front_face c)
264 v2' = v3 (front_face c)
265 v3' = v1 (front_face c)
266 fv' = rotate (Cube.fv c) cwx
268 tetrahedron4 :: Cube -> Tetrahedron
270 Tetrahedron fv' v0' v1' v2' v3'
273 v1' = center (top_face c)
274 v2' = v0 (front_face c)
275 v3' = v1 (front_face c)
276 fv' = rotate (Cube.fv c) cwy
278 tetrahedron5 :: Cube -> Tetrahedron
280 Tetrahedron fv' v0' v1' v2' v3'
283 v1' = center (top_face c)
284 v2' = v1 (top_face c)
285 v3' = v2 (top_face c)
286 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) ccwx
288 tetrahedron6 :: Cube -> Tetrahedron
290 Tetrahedron fv' v0' v1' v2' v3'
293 v1' = center (top_face c)
294 v2' = v2 (top_face c)
295 v3' = v3 (top_face c)
296 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) (ccwx . ccwx)
298 tetrahedron7 :: Cube -> Tetrahedron
300 Tetrahedron fv' v0' v1' v2' v3'
303 v1' = center (top_face c)
304 v2' = v3 (top_face c)
305 v3' = v1 (top_face c)
306 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) cwx
308 tetrahedrons :: Cube -> [Tetrahedron]