17 type t
= { x
: float; y
: float; z
: float }
23 let make x y z
= { x
= x
; y
= y
; z
= z
}
24 let elts v
= v
.x
, v
.y
, v
.z
26 let origin = { x
= 0.; y
= 0.; z
= 0. }
27 let x_axis = { origin with x
= 1. }
28 let y_axis = { origin with y
= 1. }
29 let z_axis = { origin with z
= 1. }
32 let neg v
= { x
= -.v
.x
; y
= -.v
.y
; z
= -.v
.z
}
33 let add v u
= { x
= v
.x
+ u
.x
; y
= v
.y
+ u
.y
; z
= v
.z
+ u
.z
}
34 let sub v u
= { x
= v
.x
- u
.x
; y
= v
.y
- u
.y
; z
= v
.z
- u
.z
}
35 let scale v s
= { x
= v
.x
* s
; y
= v
.y
* s
; z
= v
.z
* s
}
36 let divide v s
= { x
= v
.x
/ s
; y
= v
.y
/ s
; z
= v
.z
/ s
}
37 let cross v u
= { x
= v
.y
* u
.z
- v
.z
* u
.y
;
38 y
= v
.z
* u
.x
- v
.x
* u
.z
;
39 z
= v
.x
* u
.y
- v
.y
* u
.x
}
40 let dot v u
= v
.x
* u
.x
+ v
.y
* u
.y
+ v
.z
* u
.z
41 let magnitude_squared v
= dot v v
42 let magnitude v
= sqrt
(magnitude_squared v
)
43 let normalize v
= scale v
(1. / (magnitude v
))
46 Format.fprintf ppf
"[@[<1>x % 11f;@ y % 11f;@ z % 11f]@]" v
.x v
.y v
.z