Skip to content

Commit

Permalink
Clamp dot in angle_between to avoid precision errors.
Browse files Browse the repository at this point in the history
Fixes #3978
  • Loading branch information
Kelimion committed Jul 28, 2024
1 parent f852aac commit 24e6f16
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/math/linalg/general.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 24e6f16

Please sign in to comment.