@Override public DVectorN clone() { return new DVectorN(this); }
public DVectorN(DVectorN v2) { this(v2.v.length); set(v2.v); }
/** * 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. */ public void normalize() { if (!safeNormalizeN()) throw new IllegalStateException( "Normalization failed: " + this); }
DVectorN pm = new DVectorN(NUM); DVector3 pos1 = new DVector3(1,0,1); // point of reference (POR) DVector3 pos2 = new DVector3(-1,0,1); // point of reference (POR) pm.set(i, dRandReal()+0.1); q[i].set0(dRandReal()-0.5); q[i].set1(dRandReal()-0.5); pos1.get2()+ q[i].get2()); m.setBox (1,SIDE,SIDE,SIDE); m.adjust (pm.get(i)); particle[i].setMass (m);
private static void computeMassParams (DMass m, DVector3[] q, DVectorN pm) { int i,j; double pmi, q0, q1, q2; dMassSetZero (m); DVector3 C = m.getC().clone(); DMatrix3 I = m.getI().clone(); for (i=0; i<NUM; i++) { pmi = pm.get(i); m.setMass(m.getMass() + pmi);// += pmi; for (j=0; j<3; j++) C.add(j, pmi*q[i].get(j)); q0 = q[i].get0(); q1 = q[i].get1(); q2 = q[i].get2(); I.add(0,0, pmi*(q1*q1 + q2*q2)); I.add(1,1, pmi*(q0*q0 + q2*q2)); I.add(2,2, pmi*(q0*q0 + q1*q1)); I.sub(0,1, pmi*(q0*q1)); I.sub(0,2, pmi*(q0*q2)); I.sub(1,2, pmi*(q1*q2)); } //for (j=0; j<3; j++) m.c.v[j] /= m.mass; C.scale(1./m.getMass()); I.set(1,0, I.get(0,1)); I.set(2,0, I.get(0,2)); I.set(2,1, I.get(1,2)); m.setC(C); m.setI(I); }
setIdentity(); return false;
DVectorN pm = new DVectorN(NUM); float[] pos1 = {1,0,1}; // point of reference (POR) float[] pos2 = {-1,0,1}; // point of reference (POR) pm.set(i, dRandReal()+0.1); q[i] = new DVector3(); q[i].set(0, dRandReal()-0.5); pos1[2]+ q[i].get2()); dMassSetBox (m,1,SIDE,SIDE,SIDE); dMassAdjust (m,pm.get(i)); dBodySetMass (particle[i],m);
private static void computeMassParams (DMass m, DVector3[] q, DVectorN pm) { double pmi, q0, q1, q2; m.setZero (); DVector3 C = m.getC().clone(); DMatrix3 I = m.getI().clone(); for (int i=0; i<NUM; i++) { pmi = pm.get(i); m.setMass(m.getMass() + pmi);// += pmi; C.eqSum( C, q[i], pmi); q0 = q[i].get0(); q1 = q[i].get1(); q2 = q[i].get2(); I.add(0,0, pmi*(q1*q1 + q2*q2)); I.add(1,1, pmi*(q0*q0 + q2*q2)); I.add(2,2, pmi*(q0*q0 + q1*q1)); I.sub(0,1, pmi*(q0*q1)); I.sub(0,2, pmi*(q0*q2)); I.sub(1,2, pmi*(q1*q2)); } //for (j=0; j<3; j++) m.c.v[j] /= m.mass; C.scale(1./m.getMass()); I.set(1,0, I.get(0,1)); I.set(2,0, I.get(0,2)); I.set(2,1, I.get(1,2)); m.setC(C); m.setI(I); }
setIdentity(); return false;
@Override public DVectorN clone() { return new DVectorN(this); }
public DVectorN(DVectorN v2) { this(v2.v.length); set(v2.v); }
/** * 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. */ public void normalize() { if (!safeNormalizeN()) throw new IllegalStateException( "Normalization failed: " + this); }