fu5ha/ultraviolet

2D rotation not getting applied

elfeiin opened this issue · 3 comments

Not sure if I'm using this wrong. The following code panics:

let point = Vec2::new(1.1, 1.2);
let rotor = Rotor2::from_angle(std::f32::consts::TAU / 4.0);
assert_eq![rotor * point, Vec2::new(-1.2, 1.1)];

Output:

thread 'rotor_test' panicked at 'assertion failed: (left == right)
left: Vec2 { x: 1.1, y: 1.2 },
right: Vec2 { x: -1.2, y: 1.1 }', src/main.rs:33:5

fu5ha commented

Hm. That's odd. Admittedly, 2d rotation does not have much testing. I'll take a look...

Is this the general idea?

// Rotor2 { s: 0.70710677, bv: Bivec2 { xy: 0.70710677 } }
println!["{:?}", Rotor2::from_angle(std::f32::consts::TAU / 4.0)];

let s = 0.70710677f32;
let bv = 0.70710677f32;

let x = 1.1;
let y = 1.2;

let fx = s.mul_add(x, bv * y);
let fy = s.mul_add(y, -bv * x);
let xp = s.mul_add(fx, -bv * fy);
let yp = s.mul_add(fy, bv * fx);

// 1.1, 1.1999999
println!["{xp}, {yp}"];

let fx = s * x + bv * y;
let fy = s * y - (bv * x);
let xp = s * fx + bv * fy;
let yp = s * fy - (bv * fx);

// Hey at least the order is correct.
// Maybe just flip the signs?
// 1.1999999, -1.1
println!["{xp}, {yp}"];

This is fixed with the latest release.