cgmath icon indicating copy to clipboard operation
cgmath copied to clipboard

Basis3::from_axis_angle with unnormalized axis -> non-orthogonal matrix

Open neuschaefer opened this issue 11 years ago • 1 comments

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_angle and possibly Rotation3::from_axis_angle. Assert that axis.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).

neuschaefer avatar Mar 19 '15 15:03 neuschaefer

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.

kvark avatar Mar 19 '15 18:03 kvark