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_" ++ (show (i c)) ++ "," ++ (show (j c)) ++ "," ++ (show (k c)) ++
22 " (Center: " ++ (show (center c)) ++ ")" ++
23 " (xmin: " ++ (show (xmin c)) ++ ")" ++
24 " (xmax: " ++ (show (xmax c)) ++ ")" ++
25 " (ymin: " ++ (show (ymin c)) ++ ")" ++
26 " (ymax: " ++ (show (ymax c)) ++ ")" ++
27 " (zmin: " ++ (show (zmin c)) ++ ")" ++
28 " (zmax: " ++ (show (zmax c)) ++ ")"
31 empty_cube = Cube 0 0 0 0 empty_values
34 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
36 xmin :: Cube -> Double
37 xmin c = (2*i' - 1)*delta / 2
39 i' = fromIntegral (i c) :: Double
42 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
44 xmax :: Cube -> Double
45 xmax c = (2*i' + 1)*delta / 2
47 i' = fromIntegral (i c) :: Double
50 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
52 ymin :: Cube -> Double
53 ymin c = (2*j' - 1)*delta / 2
55 j' = fromIntegral (j c) :: Double
58 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
60 ymax :: Cube -> Double
61 ymax c = (2*j' + 1)*delta / 2
63 j' = fromIntegral (j c) :: Double
66 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
68 zmin :: Cube -> Double
69 zmin c = (2*k' - 1)*delta / 2
71 k' = fromIntegral (k c) :: Double
74 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
76 zmax :: Cube -> Double
77 zmax c = (2*k' + 1)*delta / 2
79 k' = fromIntegral (k c) :: Double
82 instance ThreeDimensional Cube where
83 -- | The center of Cube_ijk coincides with v_ijk at
84 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
88 i' = fromIntegral (i c) :: Double
89 j' = fromIntegral (j c) :: Double
90 k' = fromIntegral (k c) :: Double
96 | (x_coord p) < (xmin c) = False
97 | (x_coord p) > (xmax c) = False
98 | (y_coord p) < (ymin c) = False
99 | (y_coord p) > (ymax c) = False
100 | (z_coord p) < (zmin c) = False
101 | (z_coord p) > (zmax c) = False
105 -- instance Num Cube where
106 -- (Cube g1 i1 j1 k1 d1) + (Cube _ i2 j2 k2 d2) =
107 -- Cube g1 (i1 + i2) (j1 + j2) (k1 + k2) (d1 + d2)
109 -- (Cube g1 i1 j1 k1 d1) - (Cube _ i2 j2 k2 d2) =
110 -- Cube g1 (i1 - i2) (j1 - j2) (k1 - k2) (d1 - d2)
112 -- (Cube g1 i1 j1 k1 d1) * (Cube _ i2 j2 k2 d2) =
113 -- Cube g1 (i1 * i2) (j1 * j2) (k1 * k2) (d1 * d2)
115 -- abs (Cube g1 i1 j1 k1 d1) =
116 -- Cube g1 (abs i1) (abs j1) (abs k1) (abs d1)
118 -- signum (Cube g1 i1 j1 k1 d1) =
119 -- Cube g1 (signum i1) (signum j1) (signum k1) (signum d1)
121 -- fromInteger x = empty_cube { datum = (fromIntegral x) }
123 -- instance Fractional Cube where
124 -- (Cube g1 i1 j1 k1 d1) / (Cube _ _ _ _ d2) =
125 -- Cube g1 i1 j1 k1 (d1 / d2)
127 -- recip (Cube g1 i1 j1 k1 d1) =
128 -- Cube g1 i1 j1 k1 (recip d1)
130 -- fromRational q = empty_cube { datum = fromRational q }
134 -- | Return the cube corresponding to the grid point i,j,k. The list
135 -- of cubes is stored as [z][y][x] but we'll be requesting it by
136 -- [x][y][z] so we flip the indices in the last line.
137 -- cube_at :: Grid -> Int -> Int -> Int -> Cube
138 -- cube_at g i' j' k'
139 -- | i' >= length (function_values g) = Cube g i' j' k' 0
140 -- | i' < 0 = Cube g i' j' k' 0
141 -- | j' >= length ((function_values g) !! i') = Cube g i' j' k' 0
142 -- | j' < 0 = Cube g i' j' k' 0
143 -- | k' >= length (((function_values g) !! i') !! j') = Cube g i' j' k' 0
144 -- | k' < 0 = Cube g i' j' k' 0
146 -- (((cubes g) !! k') !! j') !! i'
155 -- | The top (in the direction of z) face of the cube.
156 top_face :: Cube -> Face
157 top_face c = Face v0' v1' v2' v3'
160 v0' = (center c) + (delta, delta, delta)
161 v1' = (center c) + (delta, -delta, delta)
162 v2' = (center c) + (-delta, -delta, delta)
163 v3' = (center c) + (-delta, delta, delta)
167 -- | The back (in the direction of x) face of the cube.
168 back_face :: Cube -> Face
169 back_face c = Face v0' v1' v2' v3'
172 v0' = (center c) + (delta, delta, delta)
173 v1' = (center c) + (delta, delta, -delta)
174 v2' = (center c) + (delta, -delta, -delta)
175 v3' = (center c) + (delta, -delta, delta)
178 -- The bottom face (in the direction of -z) of the cube.
179 down_face :: Cube -> Face
180 down_face c = Face v0' v1' v2' v3'
183 v0' = (center c) + (delta, delta, -delta)
184 v1' = (center c) + (-delta, delta, -delta)
185 v2' = (center c) + (-delta, -delta, -delta)
186 v3' = (center c) + (delta, -delta, -delta)
190 -- | The front (in the direction of -x) face of the cube.
191 front_face :: Cube -> Face
192 front_face c = Face v0' v1' v2' v3'
195 v0' = (center c) + (-delta, -delta, delta)
196 v1' = (center c) + (-delta, delta, delta)
197 v2' = (center c) + (-delta, delta, -delta)
198 v3' = (center c) + (-delta, -delta, -delta)
201 -- | The left (in the direction of -y) face of the cube.
202 left_face :: Cube -> Face
203 left_face c = Face v0' v1' v2' v3'
206 v0' = (center c) + (-delta, -delta, delta)
207 v1' = (center c) + (delta, -delta, delta)
208 v2' = (center c) + (delta, -delta, -delta)
209 v3' = (center c) + (-delta, -delta, -delta)
212 -- | The right (in the direction of y) face of the cube.
213 right_face :: Cube -> Face
214 right_face c = Face v0' v1' v2' v3'
217 v0' = (center c) + (-delta, delta, -delta)
218 v1' = (center c) + (delta, delta, -delta)
219 v2' = (center c) + (delta, delta, delta)
220 v3' = (center c) + (-delta, delta, delta)
224 tetrahedron0 :: Cube -> Tetrahedron
226 Tetrahedron (Cube.fv c) v0' v1' v2' v3'
229 v1' = center (front_face c)
230 v2' = v0 (front_face c)
231 v3' = v1 (front_face c)
233 tetrahedron1 :: Cube -> Tetrahedron
235 Tetrahedron fv' v0' v1' v2' v3'
238 v1' = center (front_face c)
239 v2' = v1 (front_face c)
240 v3' = v2 (front_face c)
241 fv' = rotate (Cube.fv c) ccwx
243 tetrahedron2 :: Cube -> Tetrahedron
245 Tetrahedron fv' v0' v1' v2' v3'
248 v1' = center (front_face c)
249 v2' = v2 (front_face c)
250 v3' = v3 (front_face c)
251 fv' = rotate (Cube.fv c) (ccwx . ccwx)
253 tetrahedron3 :: Cube -> Tetrahedron
255 Tetrahedron fv' v0' v1' v2' v3'
258 v1' = center (front_face c)
259 v2' = v3 (front_face c)
260 v3' = v1 (front_face c)
261 fv' = rotate (Cube.fv c) cwx
263 tetrahedron4 :: Cube -> Tetrahedron
265 Tetrahedron fv' v0' v1' v2' v3'
268 v1' = center (top_face c)
269 v2' = v0 (front_face c)
270 v3' = v1 (front_face c)
271 fv' = rotate (Cube.fv c) cwy
273 tetrahedron5 :: Cube -> Tetrahedron
275 Tetrahedron fv' v0' v1' v2' v3'
278 v1' = center (top_face c)
279 v2' = v1 (top_face c)
280 v3' = v2 (top_face c)
281 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) ccwx
283 tetrahedron6 :: Cube -> Tetrahedron
285 Tetrahedron fv' v0' v1' v2' v3'
288 v1' = center (top_face c)
289 v2' = v2 (top_face c)
290 v3' = v3 (top_face c)
291 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) (ccwx . ccwx)
293 tetrahedron7 :: Cube -> Tetrahedron
295 Tetrahedron fv' v0' v1' v2' v3'
298 v1' = center (top_face c)
299 v2' = v3 (top_face c)
300 v3' = v1 (top_face c)
301 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) cwx
303 tetrahedrons :: Cube -> [Tetrahedron]