cgmath
cgmath copied to clipboard
Basis3::from_axis_angle with unnormalized axis -> non-orthogonal matrix
extern crate cgmath;
use cgmath::*;
fn main() {
let axis = vec3::<f64>(1.0, 0.0, 1.0);
let a = Basis3::from_axis_angle(&axis, deg(75.0).to_rad());
let b = Basis3::from_axis_angle(&axis.normalize(), deg(75.0).to_rad());
println!("a = {:?}", a.as_matrix3());
println!("b = {:?}", b.as_matrix3());
println!("Δ = {:?}", a.as_matrix3().sub_m(b.as_matrix3()));
assert!(a.approx_eq(&b));
}
I see different ways to fix this:
- Document this behaviour in
Basis3::from_axis_angleand possiblyRotation3::from_axis_angle. Assert thataxis.length2()is approximately 1.0 at entry. - Normalize all incoming axis vectors. Document that external normalization is not required (just in case someone figures out that the algorithm needs a normalized axis vector).
Optimally, I'd like to have the normalization property enforced by the type system, like nalgebra does. In this case we'd have the axis parameter with type NormalizedVector3 or something.