Clamp dot in angle_between to avoid precision errors.

Fixes #3978
This commit is contained in:
Jeroen van Rijn
2024-07-28 15:00:29 +02:00
parent f852aac0e7
commit 24e6f16f4a

View File

@@ -275,7 +275,8 @@ to_ptr :: proc{vector_to_ptr, matrix_to_ptr}
vector_angle_between :: proc "contextless" (a, b: $V/[$N]$E) -> E {
a0 := normalize0(a)
b0 := normalize0(b)
return math.acos(dot(a0, b0))
d := clamp(dot(a0, b0), -1, +1)
return math.acos(d)
}
quaternion64_angle_between :: proc "contextless" (a, b: $Q/quaternion64) -> f16 {
c := normalize0(conj(a) * b)