/** * Gets the translate vector for this view. * @return the translate vector. */ public Vector3 getTranslate() { return new Vector3(_translate); }
public void testVector() { int ntrial = 10; for (int itrial=0; itrial<ntrial; ++itrial) { Vector3 u = randomVector3(); Vector3 v = randomVector3(); Vector3 vc = new Vector3(v); assertEquals(v,v.negate().negate()); assertEquals(v,vc.negateEquals().negateEquals()); assertEquals(1.0,v.normalize().length()); assertEquals(1.0,vc.normalizeEquals().length()); assertEquals(1.0,v.normalize().lengthSquared()); assertEquals(v.dot(v),v.lengthSquared()); assertEquals(0.0,u.cross(v).dot(u)); assertEquals(0.0,u.cross(v).dot(v)); } }
_vector = vector.normalize(); Point3 mouseNear = mouseSegment.getA(); Point3 mouseFar = mouseSegment.getB(); Vector3 mouseVector = mouseFar.minus(mouseNear).normalize(); double d = mouseVector.dot(_vector); if (d<0.0) { d = -d; _vector.negateEquals();
/** * Normalizes this vector to have unit length; makes this a unit vector. * @return this vector, normalized. */ public Vector3 normalizeEquals() { double d = length(); double s = (d>0.0)?1.0/d:1.0; x *= s; y *= s; z *= s; return this; }
/** * Returns the scaled vector s*u for this vector u. * @param s the scale factor. * @return the scaled vector. */ public Vector3 times(double s) { return new Vector3(x*s,y*s,z*s); }
public void testPoint() { int ntrial = 10; for (int itrial=0; itrial<ntrial; ++itrial) { Point3 p = randomPoint3(); Point3 pc = new Point3(p); Vector3 v = randomVector3(); assertEquals(p,p.plus(v).minus(v)); assertEquals(p,pc.plusEquals(v).minusEquals(v)); Point3 q = p.minus(v); assertEquals(q.distanceTo(p),v.length()); } }
/** * Gets the unit-vector normal to this plane. The vector points toward * the space above the plane. * @return the unit-vector normal. */ public Vector3 getNormal() { return new Vector3(_a,_b,_c); }
/** * Returns the vector difference u-v for this vector u. * @param v the other vector. * @return the vector difference u-v */ public Vector3 minus(Vector3 v) { return new Vector3(x-v.x,y-v.y,z-v.z); }
/** * Returns the vector v = p-q, for this point p and the specified point q. * @param q the point q. * @return the vector v = p-q. */ public Vector3 minus(Point3 q) { return new Vector3(x-q.x,y-q.y,z-q.z); }
/** * Returns the negation -u of this vector u. * @return the negation -u. */ public Vector3 negate() { return new Vector3(-x,-y,-z); }
/** * Returns the vector sum u+v for this vector u. * @param v the other vector. * @return the vector sum u+v */ public Vector3 plus(Vector3 v) { return new Vector3(x+v.x,y+v.y,z+v.z); }
/** * Returns the cross product of this vector u and the specified vector v. * @param v the vector v. * @return the cross product. */ public Vector3 cross(Vector3 v) { return new Vector3(y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x); } }
/** * Returns the product Mv of this matrix M and a vector v. * Uses only the upper-left 3-by-3 elements of this matrix. * @param v the vector v. * @return the product Mv. */ public Vector3 times(Vector3 v) { double vx = v.x; double vy = v.y; double vz = v.z; double ux = m[ 0]*vx + m[ 4]*vy + m[ 8]*vz; double uy = m[ 1]*vx + m[ 5]*vy + m[ 9]*vz; double uz = m[ 2]*vx + m[ 6]*vy + m[10]*vz; return new Vector3(ux,uy,uz); }
/** * Returns the product M'v of the transpose of this matrix M and a vector v. * Uses only the upper-left 3-by-3 elements of this matrix. * @param v the vector v. * @return the product M'v. */ public Vector3 transposeTimes(Vector3 v) { double vx = v.x; double vy = v.y; double vz = v.z; double ux = m[ 0]*vx + m[ 1]*vy + m[ 2]*vz; double uy = m[ 4]*vx + m[ 5]*vy + m[ 6]*vz; double uz = m[ 8]*vx + m[ 9]*vy + m[10]*vz; return new Vector3(ux,uy,uz); }
private void init() { _scale = 1.0; _translate = new Vector3(0.0,0.0,0.0); _azimuth = 40.0; _elevation = 25.0; _projection = Projection.PERSPECTIVE; _ndraw = 0; _stopwatch = new Stopwatch(); _stopwatch.start(); }