This commit is contained in:
Imbris 2021-10-15 13:17:06 -04:00
parent 76ad9f8f88
commit f61d742d29

View File

@ -204,7 +204,7 @@ impl Ori {
// NOTE: acos is very sensitive to errors at small angles
// - https://www.researchgate.net/post/How_do_I_calculate_the_smallest_angle_between_two_quaternions
// - see angle_between unit test epislons
let angle = 2.0 * between.w.min(1.0).acos();
let angle = 2.0 * between.w.min(1.0).max(-1.0).acos();
if angle < PI { angle } else { TAU - angle }
}
@ -300,6 +300,10 @@ fn rotation_2d(Vec2 { x, y }: Vec2<f32>, axis: Vec3<f32>) -> Quaternion<f32> {
// vector = vec3(0, 0, 1) * +/- sqrt((1 - cos(a)) / 2)
//
// cos(a) = x / |xy| => x (when normalized)
// Prevent NaNs from negative sqrt (float errors can put this slightly over 1.0)
let x = x.min(1.0).max(-1.0);
let scalar = ((1.0 + x) / 2.0).sqrt() * y.signum();
let vector = axis * ((1.0 - x) / 2.0).sqrt();