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
113 -- | The top (in the direction of z) face of the cube.
114 top_face :: Cube -> Face
115 top_face c = Face v0' v1' v2' v3'
118 v0' = (center c) + (delta, delta, delta)
119 v1' = (center c) + (delta, -delta, delta)
120 v2' = (center c) + (-delta, -delta, delta)
121 v3' = (center c) + (-delta, delta, delta)
125 -- | The back (in the direction of x) face of the cube.
126 back_face :: Cube -> Face
127 back_face c = Face v0' v1' v2' v3'
130 v0' = (center c) + (delta, delta, delta)
131 v1' = (center c) + (delta, delta, -delta)
132 v2' = (center c) + (delta, -delta, -delta)
133 v3' = (center c) + (delta, -delta, delta)
136 -- The bottom face (in the direction of -z) of the cube.
137 down_face :: Cube -> Face
138 down_face c = Face v0' v1' v2' v3'
141 v0' = (center c) + (delta, delta, -delta)
142 v1' = (center c) + (-delta, delta, -delta)
143 v2' = (center c) + (-delta, -delta, -delta)
144 v3' = (center c) + (delta, -delta, -delta)
148 -- | The front (in the direction of -x) face of the cube.
149 front_face :: Cube -> Face
150 front_face c = Face v0' v1' v2' v3'
153 v0' = (center c) + (-delta, -delta, delta)
154 v1' = (center c) + (-delta, delta, delta)
155 v2' = (center c) + (-delta, delta, -delta)
156 v3' = (center c) + (-delta, -delta, -delta)
159 -- | The left (in the direction of -y) face of the cube.
160 left_face :: Cube -> Face
161 left_face c = 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
172 right_face c = 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)
182 tetrahedron0 :: Cube -> Tetrahedron
184 Tetrahedron (Cube.fv c) v0' v1' v2' v3'
187 v1' = center (front_face c)
188 v2' = v0 (front_face c)
189 v3' = v1 (front_face c)
191 tetrahedron1 :: Cube -> Tetrahedron
193 Tetrahedron fv' v0' v1' v2' v3'
196 v1' = center (front_face c)
197 v2' = v1 (front_face c)
198 v3' = v2 (front_face c)
199 fv' = rotate (Cube.fv c) ccwx
201 tetrahedron2 :: Cube -> Tetrahedron
203 Tetrahedron fv' v0' v1' v2' v3'
206 v1' = center (front_face c)
207 v2' = v2 (front_face c)
208 v3' = v3 (front_face c)
209 fv' = rotate (Cube.fv c) (ccwx . ccwx)
211 tetrahedron3 :: Cube -> Tetrahedron
213 Tetrahedron fv' v0' v1' v2' v3'
216 v1' = center (front_face c)
217 v2' = v3 (front_face c)
218 v3' = v1 (front_face c)
219 fv' = rotate (Cube.fv c) cwx
221 tetrahedron4 :: Cube -> Tetrahedron
223 Tetrahedron fv' v0' v1' v2' v3'
226 v1' = center (top_face c)
227 v2' = v0 (front_face c)
228 v3' = v1 (front_face c)
229 fv' = rotate (Cube.fv c) cwy
231 tetrahedron5 :: Cube -> Tetrahedron
233 Tetrahedron fv' v0' v1' v2' v3'
236 v1' = center (top_face c)
237 v2' = v1 (top_face c)
238 v3' = v2 (top_face c)
239 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) ccwx
241 tetrahedron6 :: Cube -> Tetrahedron
243 Tetrahedron fv' v0' v1' v2' v3'
246 v1' = center (top_face c)
247 v2' = v2 (top_face c)
248 v3' = v3 (top_face c)
249 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) (ccwx . ccwx)
251 tetrahedron7 :: Cube -> Tetrahedron
253 Tetrahedron fv' v0' v1' v2' v3'
256 v1' = center (top_face c)
257 v2' = v3 (top_face c)
258 v3' = v1 (top_face c)
259 fv' = rotate (Tetrahedron.fv (tetrahedron0 c)) cwx
261 tetrahedrons :: Cube -> [Tetrahedron]