Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | |
2 | exception Error | |
3 | ||
4 | fun translateXYZ (translateX : real, translateY : real, translateZ : real) = | |
5 | ((1.0, 0.0, 0.0, translateX), | |
6 | (0.0, 1.0, 0.0, translateY), | |
7 | (0.0, 0.0, 1.0, translateZ), | |
8 | (0.0, 0.0, 0.0, 1.0)) | |
9 | ||
10 | fun transformPoint matr {x, y, z} = | |
11 | let | |
12 | val ((in00, in01, in02, in03), | |
13 | (in10, in11, in12, in13), | |
14 | (in20, in21, in22, in23), | |
15 | (in30, in31, in32, in33)) = matr | |
16 | ||
17 | val w = x * in30 + y * in31 + z * in32 + in33 | |
18 | in | |
19 | if Real.== (0.0, w) then | |
20 | raise Error | |
21 | else | |
22 | {x = ((in00 * x) + (in01 * y) + (in02 * z) + in03) / w, | |
23 | y = ((in10 * x) + (in11 * y) + (in12 * z) + in13) / w, | |
24 | z = ((in20 * x) + (in21 * y) + (in22 * z) + in23) / w} | |
25 | end | |
26 | ||
27 | fun Point3DToString {x, y, z} = | |
28 | "{x = " ^ (Real.toString x) ^ | |
29 | ", y = " ^ (Real.toString y) ^ | |
30 | ", z = " ^ (Real.toString z) ^ | |
31 | "}\n" | |
32 | ||
33 | val m = translateXYZ (2.0, 3.0, 4.0) | |
34 | val p = {x = 1.0, y = 2.0, z = 3.0} | |
35 | val _ = print (Point3DToString p) | |
36 | val p' = transformPoint m p | |
37 | val _ = print (Point3DToString p') |