Add a trait method to normalize representations
This corrects the dispatching of the normalization routine for spheres, and it adds a (perhaps redundant) normalization routine for points.
This commit is contained in:
parent
2adf4669f4
commit
c263d5b8a6
2 changed files with 31 additions and 14 deletions
|
@ -34,6 +34,21 @@ pub fn sphere_with_offset(dir_x: f64, dir_y: f64, dir_z: f64, off: f64, curv: f6
|
|||
])
|
||||
}
|
||||
|
||||
// normalize a sphere's representation vector by contracting toward the last
|
||||
// coordinate axis
|
||||
pub fn normalize_mut_sphere(rep: &mut DVector<f64>) {
|
||||
let q_sp = rep.fixed_rows::<3>(0).norm_squared();
|
||||
let half_q_lt = -2.0 * rep[3] * rep[4];
|
||||
let half_q_lt_sq = half_q_lt * half_q_lt;
|
||||
let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt();
|
||||
rep.fixed_rows_mut::<4>(0).scale_mut(1.0 / scaling);
|
||||
}
|
||||
|
||||
// normalize a point's representation vector by scaling
|
||||
pub fn normalize_mut_point(rep: &mut DVector<f64>) {
|
||||
rep.scale_mut(0.5 / rep[3]);
|
||||
}
|
||||
|
||||
// given a sphere's representation vector, change the sphere's half-curvature to
|
||||
// `half-curv` and then restore normalization by contracting the representation
|
||||
// vector toward the curvature axis
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue