8 import ThreeDimensional
10 data Cube = Cube { h :: Double,
14 fv :: FunctionValues }
18 instance Show Cube where
20 "Cube_" ++ (show (i c)) ++ "," ++ (show (j c)) ++ "," ++ (show (k c)) ++
21 " (Center: " ++ (show (center c)) ++ ")" ++
22 " (xmin: " ++ (show (xmin c)) ++ ")" ++
23 " (xmax: " ++ (show (xmax c)) ++ ")" ++
24 " (ymin: " ++ (show (ymin c)) ++ ")" ++
25 " (ymax: " ++ (show (ymax c)) ++ ")" ++
26 " (zmin: " ++ (show (zmin c)) ++ ")" ++
27 " (zmax: " ++ (show (zmax c)) ++ ")"
30 empty_cube = Cube 0 0 0 0 empty_values
33 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder,
35 xmin :: Cube -> Double
36 xmin c = (2*i' - 1)*delta / 2
38 i' = fromIntegral (i c) :: Double
41 -- | The right-side boundary of the cube. See Sorokina and Zeilfelder,
43 xmax :: Cube -> Double
44 xmax c = (2*i' + 1)*delta / 2
46 i' = fromIntegral (i c) :: Double
49 -- | The front boundary of the cube. See Sorokina and Zeilfelder,
51 ymin :: Cube -> Double
52 ymin c = (2*j' - 1)*delta / 2
54 j' = fromIntegral (j c) :: Double
57 -- | The back boundary of the cube. See Sorokina and Zeilfelder,
59 ymax :: Cube -> Double
60 ymax c = (2*j' + 1)*delta / 2
62 j' = fromIntegral (j c) :: Double
65 -- | The bottom boundary of the cube. See Sorokina and Zeilfelder,
67 zmin :: Cube -> Double
68 zmin c = (2*k' - 1)*delta / 2
70 k' = fromIntegral (k c) :: Double
73 -- | The top boundary of the cube. See Sorokina and Zeilfelder,
75 zmax :: Cube -> Double
76 zmax c = (2*k' + 1)*delta / 2
78 k' = fromIntegral (k c) :: Double
81 instance ThreeDimensional Cube where
82 -- | The center of Cube_ijk coincides with v_ijk at
83 -- (ih, jh, kh). See Sorokina and Zeilfelder, p. 76.
87 i' = fromIntegral (i c) :: Double
88 j' = fromIntegral (j c) :: Double
89 k' = fromIntegral (k c) :: Double
95 | (x_coord p) < (xmin c) = False
96 | (x_coord p) > (xmax c) = False
97 | (y_coord p) < (ymin c) = False
98 | (y_coord p) > (ymax c) = False
99 | (z_coord p) < (zmin c) = False
100 | (z_coord p) > (zmax c) = False
104 -- instance Num Cube where
105 -- (Cube g1 i1 j1 k1 d1) + (Cube _ i2 j2 k2 d2) =
106 -- Cube g1 (i1 + i2) (j1 + j2) (k1 + k2) (d1 + d2)
108 -- (Cube g1 i1 j1 k1 d1) - (Cube _ i2 j2 k2 d2) =
109 -- Cube g1 (i1 - i2) (j1 - j2) (k1 - k2) (d1 - d2)
111 -- (Cube g1 i1 j1 k1 d1) * (Cube _ i2 j2 k2 d2) =
112 -- Cube g1 (i1 * i2) (j1 * j2) (k1 * k2) (d1 * d2)
114 -- abs (Cube g1 i1 j1 k1 d1) =
115 -- Cube g1 (abs i1) (abs j1) (abs k1) (abs d1)
117 -- signum (Cube g1 i1 j1 k1 d1) =
118 -- Cube g1 (signum i1) (signum j1) (signum k1) (signum d1)
120 -- fromInteger x = empty_cube { datum = (fromIntegral x) }
122 -- instance Fractional Cube where
123 -- (Cube g1 i1 j1 k1 d1) / (Cube _ _ _ _ d2) =
124 -- Cube g1 i1 j1 k1 (d1 / d2)
126 -- recip (Cube g1 i1 j1 k1 d1) =
127 -- Cube g1 i1 j1 k1 (recip d1)
129 -- fromRational q = empty_cube { datum = fromRational q }
133 -- | Return the cube corresponding to the grid point i,j,k. The list
134 -- of cubes is stored as [z][y][x] but we'll be requesting it by
135 -- [x][y][z] so we flip the indices in the last line.
136 -- cube_at :: Grid -> Int -> Int -> Int -> Cube
137 -- cube_at g i' j' k'
138 -- | i' >= length (function_values g) = Cube g i' j' k' 0
139 -- | i' < 0 = Cube g i' j' k' 0
140 -- | j' >= length ((function_values g) !! i') = Cube g i' j' k' 0
141 -- | j' < 0 = Cube g i' j' k' 0
142 -- | k' >= length (((function_values g) !! i') !! j') = Cube g i' j' k' 0
143 -- | k' < 0 = Cube g i' j' k' 0
145 -- (((cubes g) !! k') !! j') !! i'
154 -- | The top (in the direction of z) face of the cube.
155 top_face :: Cube -> Face
156 top_face c = Face v0' v1' v2' v3'
159 v0' = (center c) + (-delta, delta, delta)
160 v1' = (center c) + (delta, delta, delta)
161 v2' = (center c) + (delta, -delta, delta)
162 v3' = (center c) + (-delta, -delta, delta)
166 -- | The back (in the direction of x) face of the cube.
167 back_face :: Cube -> Face
168 back_face c = Face v0' v1' v2' v3'
171 v0' = (center c) + (delta, delta, delta)
172 v1' = (center c) + (delta, delta, -delta)
173 v2' = (center c) + (delta, -delta, -delta)
174 v3' = (center c) + (delta, -delta, delta)
177 -- The bottom face (in the direction of -z) of the cube.
178 down_face :: Cube -> Face
179 down_face c = Face v0' v1' v2' v3'
182 v0' = (center c) + (delta, delta, -delta)
183 v1' = (center c) + (-delta, delta, -delta)
184 v2' = (center c) + (-delta, -delta, -delta)
185 v3' = (center c) + (delta, -delta, -delta)
189 -- | The front (in the direction of -x) face of the cube.
190 front_face :: Cube -> Face
191 front_face c = Face v0' v1' v2' v3'
194 v0' = (center c) + (-delta, delta, -delta)
195 v1' = (center c) + (-delta, delta, delta)
196 v2' = (center c) + (-delta, -delta, delta)
197 v3' = (center c) + (-delta, -delta, -delta)
200 -- | The left (in the direction of -y) face of the cube.
201 left_face :: Cube -> Face
202 left_face c = Face v0' v1' v2' v3'
205 v0' = (center c) + (-delta, -delta, delta)
206 v1' = (center c) + (delta, -delta, delta)
207 v2' = (center c) + (delta, -delta, -delta)
208 v3' = (center c) + (-delta, -delta, -delta)
211 -- | The right (in the direction of y) face of the cube.
212 right_face :: Cube -> Face
213 right_face c = Face v0' v1' v2' v3'
216 v0' = (center c) + (-delta, delta, -delta)
217 v1' = (center c) + (delta, delta, -delta)
218 v2' = (center c) + (delta, delta, delta)
219 v3' = (center c) + (-delta, delta, delta)