Created
November 12, 2019 10:30
-
-
Save bitshifter/ea089bb49a57f0e94a44c657e821f9e1 to your computer and use it in GitHub Desktop.
unit quaternion drift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use glam; | |
use rand::{thread_rng, Rng}; | |
fn rand_angle<R: Rng>(rng: &mut R) -> f32 { | |
rng.gen_range(-std::f32::consts::PI, std::f32::consts::PI) | |
} | |
fn rand_quat<R: Rng>(rng: &mut R) -> glam::Quat { | |
let yaw = rand_angle(rng); | |
let pitch = rand_angle(rng); | |
let roll = rand_angle(rng); | |
let result = glam::Quat::from_rotation_ypr(yaw, pitch, roll); | |
assert!(result.is_normalized()); | |
result | |
} | |
fn main() { | |
let mut rng = thread_rng(); | |
let mut result = rand_quat(&mut rng); | |
let mut i = 0; | |
loop { | |
let a = result; | |
let b = rand_quat(&mut rng); | |
result = a * b; | |
if !result.is_normalized() { | |
println!("{}: {} * {} = {} |{}|", i, a, b, result, result.length()); | |
break; | |
} | |
i += 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment