/** * this may be called for vectors `a' with extremely small magnitude, for * example the result of a cross product on two nearly perpendicular vectors. * we must be robust to these small vectors. to prevent numerical error, * first find the component a[i] with the largest magnitude and then scale * all the components by 1/a[i]. then we can compute the length of `a' and * scale the components by 1/l. this has been verified to work with vectors * containing the smallest representable numbers. * * This method throws an IllegalArgumentEception if no normal can be determined. */ public final void normalize() { if (!safeNormalize()) throw new IllegalStateException( "Normalization failed: " + this); }
/** * this may be called for vectors `a' with extremely small magnitude, for * example the result of a cross product on two nearly perpendicular vectors. * we must be robust to these small vectors. to prevent numerical error, * first find the component a[i] with the largest magnitude and then scale * all the components by 1/a[i]. then we can compute the length of `a' and * scale the components by 1/l. this has been verified to work with vectors * containing the smallest representable numbers. * * This method throws an IllegalArgumentEception if no normal can be determined. */ public final void normalize() { if (!safeNormalize()) throw new IllegalStateException( "Normalization failed: " + this); }
/** * @param baseAxis - base axis for constraints * @param body2Axis - main axis of the 2nd body */ public void setAxes(DVector3 baseAxis, DVector3 body2Axis) { baseAxis.safeNormalize(); body2Axis.safeNormalize(); DVector3 twistUpAxis = new DVector3(); if (Math.abs(body2Axis.dot(new DVector3(0.0, 1.0, 0.0))) < 0.7) { twistUpAxis.set(0, 1, 0); } else { twistUpAxis.set(0, 0, 1); } DVector3 cross = new DVector3(); cross.eqCross(body2Axis, twistUpAxis); cross.safeNormalize(); twistUpAxis.eqCross(cross, body2Axis); twistUpAxis.safeNormalize(); setAxes(baseAxis, this.baseAxis, null); setAxes(body2Axis, null, this.body2Axis); setAxes(twistUpAxis, twistUpAxis1, twistUpAxis2); }
/** * @param baseAxis - base axis for constraints * @param body2Axis - main axis of the 2nd body */ public void setAxes(DVector3 baseAxis, DVector3 body2Axis) { baseAxis.safeNormalize(); body2Axis.safeNormalize(); DVector3 twistUpAxis = new DVector3(); if (Math.abs(body2Axis.dot(new DVector3(0.0, 1.0, 0.0))) < 0.7) { twistUpAxis.set(0, 1, 0); } else { twistUpAxis.set(0, 0, 1); } DVector3 cross = new DVector3(); cross.eqCross(body2Axis, twistUpAxis); cross.safeNormalize(); twistUpAxis.eqCross(cross, body2Axis); twistUpAxis.safeNormalize(); setAxes(baseAxis, this.baseAxis, null); setAxes(body2Axis, null, this.body2Axis); setAxes(twistUpAxis, twistUpAxis1, twistUpAxis2); }
private DVector3 getDragForce(double density, DBody odeBody, double area) { DVector3 dragForce = new DVector3(odeBody.getLinearVel()); double lvel = dragForce.length(); dragForce.safeNormalize(); dragForce.scale(-0.5 * density * area * lvel * lvel * 0.5); return dragForce; }
private DVector3 getDragTorque(double density, DBody odeBody, double area) { DVector3 dragTorque = new DVector3(odeBody.getAngularVel()); double avel = dragTorque.length(); dragTorque.safeNormalize(); dragTorque.scale(-0.5 * density * area * avel * avel * 0.5); return dragTorque; }
getAxis2(twist, body2Axis); dCalcVectorCross3(axis1, twist, flex); axis1.safeNormalize(); double angle = limitingFlex ? Math.acos(flex.dot(twist)) : 0; if (limotFlex.testRotationalLimit(angle)) { if (limotTwist.testRotationalLimit(angle2)) { dCalcVectorCross3(axis2, twistUpB2, projected); axis2.safeNormalize(); info.incM();
getAxis2(twist, body2Axis); dCalcVectorCross3(axis1, twist, flex); axis1.safeNormalize(); double angle = limitingFlex ? Math.acos(flex.dot(twist)) : 0; if (limotFlex.testRotationalLimit(angle)) { if (limotTwist.testRotationalLimit(angle2)) { dCalcVectorCross3(axis2, twistUpB2, projected); axis2.safeNormalize(); info.incM();
geom.setBody(body); DVector3 za = new DVector3(p2); (za.sub(p1)).safeNormalize(); DVector3 xa; DVector3 ya; ya = new DVector3(); ya.eqCross(za, xa); ya.safeNormalize(); xa.eqCross(ya, za); } else { xa = new DVector3(); xa.eqCross(ya, za); xa.safeNormalize(); ya.eqCross(za, xa);
geom.setBody(body); DVector3 za = new DVector3(p2); (za.sub(p1)).safeNormalize(); DVector3 xa; DVector3 ya; ya = new DVector3(); ya.eqCross(za, xa); ya.safeNormalize(); xa.eqCross(ya, za); } else { xa = new DVector3(); xa.eqCross(ya, za); xa.safeNormalize(); ya.eqCross(za, xa);
cross.safeNormalize(); upAxis.eqCross(cross, contact.normal); upAxis.safeNormalize(); DVector3 perturbed = new DVector3(); DVector3 pos = new DVector3(contact.pos);
cross.safeNormalize(); upAxis.eqCross(cross, contact.normal); upAxis.safeNormalize(); DVector3 perturbed = new DVector3(); DVector3 pos = new DVector3(contact.pos);
contact.normal.safeNormalize();
contact.normal.safeNormalize();