/** * @param point * @return the distance from this plane to a provided point. If the point is on the negative side of the plane the * distance returned is negative, otherwise it is positive. If the point is on the plane, it is zero. * @throws NullPointerException * if point is null. */ @Override public double pseudoDistance(final ReadOnlyVector3 point) { return _normal.dot(point) - _constant; }
/** * @param point * @return the distance from this plane to a provided point. If the point is on the negative side of the plane the * distance returned is negative, otherwise it is positive. If the point is on the plane, it is zero. * @throws NullPointerException * if point is null. */ @Override public double pseudoDistance(final ReadOnlyVector3 point) { return _normal.dot(point) - _constant; }
/** * @param otherVector * a unit vector to find the angle against * @return the minimum angle (in radians) between two vectors. It is assumed that both this vector and the given * vector are unit vectors (normalized). * @throws NullPointerException * if otherVector is null. */ @Override public double smallestAngleBetween(final ReadOnlyVector3 otherVector) { return MathUtils.acos(dot(otherVector)); }
/** * @param otherVector * a unit vector to find the angle against * @return the minimum angle (in radians) between two vectors. It is assumed that both this vector and the given * vector are unit vectors (normalized). * @throws NullPointerException * if otherVector is null. */ @Override public double smallestAngleBetween(final ReadOnlyVector3 otherVector) { return MathUtils.acos(dot(otherVector)); }
@Override public boolean contains(final ReadOnlyVector3 point) { _compVect1.set(point).subtractLocal(_center); double coeff = _compVect1.dot(_xAxis); if (Math.abs(coeff) > _extent.getX()) { return false; } coeff = _compVect1.dot(_yAxis); if (Math.abs(coeff) > _extent.getY()) { return false; } coeff = _compVect1.dot(_zAxis); if (Math.abs(coeff) > _extent.getZ()) { return false; } return true; }
@Override public boolean contains(final ReadOnlyVector3 point) { _compVect1.set(point).subtractLocal(_center); double coeff = _compVect1.dot(_xAxis); if (Math.abs(coeff) > _extent.getX()) { return false; } coeff = _compVect1.dot(_yAxis); if (Math.abs(coeff) > _extent.getY()) { return false; } coeff = _compVect1.dot(_zAxis); if (Math.abs(coeff) > _extent.getZ()) { return false; } return true; }
/** * @param vec * @return the dot product of this vector with the x, y, z values of the given vector. * @throws NullPointerException * if vec is null. */ @Override public double dot(final ReadOnlyVector3 vec) { return dot(vec.getX(), vec.getY(), vec.getZ()); }
/** * @param vec * @return the dot product of this vector with the x, y, z values of the given vector. * @throws NullPointerException * if vec is null. */ @Override public double dot(final ReadOnlyVector3 vec) { return dot(vec.getX(), vec.getY(), vec.getZ()); }
@Override public boolean intersects(final ReadOnlyRay3 ray) { if (!Vector3.isValid(_center)) { return false; } final Vector3 diff = ray.getOrigin().subtract(getCenter(), _compVect1); final double radiusSquared = getRadius() * getRadius(); final double a = diff.dot(diff) - radiusSquared; if (a <= 0.0) { // in sphere return true; } // outside sphere final Vector3 dir = _compVect2.set(ray.getDirection()); final double b = dir.dot(diff); if (b >= 0.0) { return false; } return b * b >= a; }
@Override public boolean intersects(final ReadOnlyRay3 ray) { if (!Vector3.isValid(_center)) { return false; } final Vector3 diff = ray.getOrigin().subtract(getCenter(), _compVect1); final double radiusSquared = getRadius() * getRadius(); final double a = diff.dot(diff) - radiusSquared; if (a <= 0.0) { // in sphere return true; } // outside sphere final Vector3 dir = _compVect2.set(ray.getDirection()); final double b = dir.dot(diff); if (b >= 0.0) { return false; } return b * b >= a; }
/** * Reflects an incoming vector across the normal of this Plane. * * @param unitVector * the incoming vector. Must be a unit vector. * @param store * optional Vector to store the result in. May be the same as the unitVector. * @return the reflected vector. */ @Override public Vector3 reflectVector(final ReadOnlyVector3 unitVector, final Vector3 store) { Vector3 result = store; if (result == null) { result = new Vector3(); } final double dotProd = _normal.dot(unitVector) * 2; result.set(unitVector).subtractLocal(_normal.getX() * dotProd, _normal.getY() * dotProd, _normal.getZ() * dotProd); return result; }
/** * Reflects an incoming vector across the normal of this Plane. * * @param unitVector * the incoming vector. Must be a unit vector. * @param store * optional Vector to store the result in. May be the same as the unitVector. * @return the reflected vector. */ @Override public Vector3 reflectVector(final ReadOnlyVector3 unitVector, final Vector3 store) { Vector3 result = store; if (result == null) { result = new Vector3(); } final double dotProd = _normal.dot(unitVector) * 2; result.set(unitVector).subtractLocal(_normal.getX() * dotProd, _normal.getY() * dotProd, _normal.getZ() * dotProd); return result; }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } final Vector3 diff = _compVect1.set(getCenter()).subtractLocal(bs.getCenter()); final double rsum = getRadius() + bs.getRadius(); return (diff.dot(diff) <= rsum * rsum); }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } final Vector3 diff = _compVect1.set(getCenter()).subtractLocal(bs.getCenter()); final double rsum = getRadius() + bs.getRadius(); return (diff.dot(diff) <= rsum * rsum); }
/** * Updates the value of our view matrix. */ protected void updateViewMatrix() { _view.setIdentity(); _view.setM00(-_left.getX()); _view.setM10(-_left.getY()); _view.setM20(-_left.getZ()); _view.setM01(_up.getX()); _view.setM11(_up.getY()); _view.setM21(_up.getZ()); _view.setM02(-_direction.getX()); _view.setM12(-_direction.getY()); _view.setM22(-_direction.getZ()); _view.setM30(_left.dot(_location)); _view.setM31(-_up.dot(_location)); _view.setM32(_direction.dot(_location)); }
/** * Updates the value of our model view matrix. */ protected void updateModelViewMatrix() { _modelView.setIdentity(); _modelView.setM00(-_left.getX()); _modelView.setM10(-_left.getY()); _modelView.setM20(-_left.getZ()); _modelView.setM01(_up.getX()); _modelView.setM11(_up.getY()); _modelView.setM21(_up.getZ()); _modelView.setM02(-_direction.getX()); _modelView.setM12(-_direction.getY()); _modelView.setM22(-_direction.getZ()); _modelView.setM30(_left.dot(_location)); _modelView.setM31(-_up.dot(_location)); _modelView.setM32(_direction.dot(_location)); }
/** * Sets this plane to the plane defined by the given three points. * * @param pointA * @param pointB * @param pointC * @return this plane for chaining * @throws NullPointerException * if one or more of the points are null. */ public Plane setPlanePoints(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB, final ReadOnlyVector3 pointC) { _normal.set(pointB).subtractLocal(pointA); _normal.crossLocal(pointC.getX() - pointA.getX(), pointC.getY() - pointA.getY(), pointC.getZ() - pointA.getZ()) .normalizeLocal(); _constant = _normal.dot(pointA); return this; }
/** * Sets this plane to the plane defined by the given three points. * * @param pointA * @param pointB * @param pointC * @return this plane for chaining * @throws NullPointerException * if one or more of the points are null. */ public Plane setPlanePoints(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB, final ReadOnlyVector3 pointC) { _normal.set(pointB).subtractLocal(pointA); _normal.crossLocal(pointC.getX() - pointA.getX(), pointC.getY() - pointA.getY(), pointC.getZ() - pointA.getZ()) .normalizeLocal(); _constant = _normal.dot(pointA); return this; }
/** * @param point * @param store * if not null, the closest point is stored in this param * @return the squared distance from this line to the given point. * @throws NullPointerException * if the point is null. */ public double distanceSquared(final ReadOnlyVector3 point, final Vector3 store) { final Vector3 vectorA = Vector3.fetchTempInstance(); vectorA.set(point).subtractLocal(_origin); // Note: assumes direction is normalized final double t0 = _direction.dot(vectorA); // d = |P - (O + t*D)| vectorA.set(_direction).multiplyLocal(t0); vectorA.addLocal(_origin); // Save away the closest point if requested. if (store != null) { store.set(vectorA); } point.subtract(vectorA, vectorA); final double lSQ = vectorA.lengthSquared(); Vector3.releaseTempInstance(vectorA); return lSQ; }