forked from StudioInfinity/dyna3
Compare commits
No commits in common. "955220c0bc43256fe7e47b38f7f26ca2c6a77af8" and "e1952d7d5217b9d06abc0bd9734a61af637496da" have entirely different histories.
955220c0bc
...
e1952d7d52
2 changed files with 35 additions and 42 deletions
|
@ -8,7 +8,6 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
|||
use crate::{
|
||||
engine::{
|
||||
Q,
|
||||
change_half_curvature,
|
||||
local_unif_to_std,
|
||||
realize_gram,
|
||||
sphere,
|
||||
|
@ -402,9 +401,37 @@ impl Assembly {
|
|||
let representation = self_for_effect.elements.with_untracked(
|
||||
|elts| elts[subject].representation
|
||||
);
|
||||
representation.update(
|
||||
|rep| change_half_curvature(rep, half_curv)
|
||||
representation.update(|rep| {
|
||||
// set the sphere's half-curvature to the desired value
|
||||
rep[3] = half_curv;
|
||||
|
||||
// restore normalization by contracting toward the curvature
|
||||
// axis
|
||||
const SIZE_THRESHOLD: f64 = 1e-9;
|
||||
let half_q_lt = -2.0 * half_curv * rep[4];
|
||||
let half_q_lt_sq = half_q_lt * half_q_lt;
|
||||
let mut spatial = rep.fixed_rows_mut::<3>(0);
|
||||
let q_sp = spatial.norm_squared();
|
||||
if q_sp < SIZE_THRESHOLD && half_q_lt_sq < SIZE_THRESHOLD {
|
||||
spatial.copy_from_slice(
|
||||
&[0.0, 0.0, (1.0 - 2.0 * half_q_lt).sqrt()]
|
||||
);
|
||||
} else {
|
||||
let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt();
|
||||
spatial.scale_mut(1.0 / scaling);
|
||||
rep[4] /= scaling;
|
||||
}
|
||||
|
||||
/* DEBUG */
|
||||
// verify normalization
|
||||
let rep_for_debug = rep.clone();
|
||||
console::log_1(&JsValue::from(
|
||||
format!(
|
||||
"Sphere self-product after curvature change: {}",
|
||||
rep_for_debug.dot(&(&*Q * &rep_for_debug))
|
||||
)
|
||||
));
|
||||
});
|
||||
self_for_effect.realize();
|
||||
}
|
||||
});
|
||||
|
@ -422,16 +449,16 @@ impl Assembly {
|
|||
|
||||
// set up the constraint problem
|
||||
let problem = self.elements.with_untracked(|elts| {
|
||||
let mut problem = ConstraintProblem::new(elts.len());
|
||||
let mut problem_to_be = ConstraintProblem::new(elts.len());
|
||||
for (_, elt) in elts {
|
||||
elt.pose(&mut problem, elts);
|
||||
elt.pose(&mut problem_to_be, elts);
|
||||
}
|
||||
self.regulators.with_untracked(|regs| {
|
||||
for (_, reg) in regs {
|
||||
reg.pose(&mut problem, elts);
|
||||
reg.pose(&mut problem_to_be, elts);
|
||||
}
|
||||
});
|
||||
problem
|
||||
problem_to_be
|
||||
});
|
||||
|
||||
/* DEBUG */
|
||||
|
|
|
@ -35,40 +35,6 @@ pub fn sphere_with_offset(dir_x: f64, dir_y: f64, dir_z: f64, off: f64, curv: f6
|
|||
])
|
||||
}
|
||||
|
||||
// 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
|
||||
pub fn change_half_curvature(rep: &mut DVector<f64>, half_curv: f64) {
|
||||
// set the sphere's half-curvature to the desired value
|
||||
rep[3] = half_curv;
|
||||
|
||||
// restore normalization by contracting toward the curvature axis
|
||||
const SIZE_THRESHOLD: f64 = 1e-9;
|
||||
let half_q_lt = -2.0 * half_curv * rep[4];
|
||||
let half_q_lt_sq = half_q_lt * half_q_lt;
|
||||
let mut spatial = rep.fixed_rows_mut::<3>(0);
|
||||
let q_sp = spatial.norm_squared();
|
||||
if q_sp < SIZE_THRESHOLD && half_q_lt_sq < SIZE_THRESHOLD {
|
||||
spatial.copy_from_slice(
|
||||
&[0.0, 0.0, (1.0 - 2.0 * half_q_lt).sqrt()]
|
||||
);
|
||||
} else {
|
||||
let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt();
|
||||
spatial.scale_mut(1.0 / scaling);
|
||||
rep[4] /= scaling;
|
||||
}
|
||||
|
||||
/* DEBUG */
|
||||
// verify normalization
|
||||
let rep_for_debug = rep.clone();
|
||||
console::log_1(&JsValue::from(
|
||||
format!(
|
||||
"Sphere self-product after curvature change: {}",
|
||||
rep_for_debug.dot(&(&*Q * &rep_for_debug))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
// --- partial matrices ---
|
||||
|
||||
pub struct MatrixEntry {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue