Simplify put_object
This commit is contained in:
parent
0efa513130
commit
f06e502e26
|
|
@ -148,15 +148,10 @@ fn rel_to_abs(space: &impl Metric, base: &Location, rel: Vec2, steps: usize) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a position and a rotation to a [Location]. Only the X direction is preserved from `rot` to ensure the resulting Location describes an orthonormal coordinate system.
|
/// Converts a position and a rotation to a [Location]. Only the X direction is preserved from `rot` to ensure the resulting Location describes an orthonormal coordinate system.
|
||||||
///
|
|
||||||
/// Mathematically, returned `rot` is `M^-1 * orthonormalize(M * rot)` where `M^2` is the metric tensor.
|
|
||||||
fn put_object(space: &impl Metric, pos: Vec2, rot: Mat2) -> Location {
|
fn put_object(space: &impl Metric, pos: Vec2, rot: Mat2) -> Location {
|
||||||
let x_dir = rot.x_axis;
|
|
||||||
let metric_sqrt = Mat2::from(space.sqrt_at(pos));
|
let metric_sqrt = Mat2::from(space.sqrt_at(pos));
|
||||||
let metric_inv_sqrt = Mat2::from(space.sqrt_at(pos).inverse());
|
let metric_inv_sqrt = Mat2::from(space.sqrt_at(pos).inverse());
|
||||||
let fx = (metric_sqrt * x_dir).normalize();
|
let rot = metric_inv_sqrt * (metric_sqrt * rot).orthonormalize();
|
||||||
let fy = vec2(-fx.y, fx.x); // TODO: respect orientation of `rot`
|
|
||||||
let rot = metric_inv_sqrt * mat2(fx, fy);
|
|
||||||
Location { pos, rot }
|
Location { pos, rot }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user