public PlaneSide getPointSide(Vector3 point) { double distance = Vector3.dot(mNormal, point) + mD; if(distance == 0) return PlaneSide.ONPLANE; else if(distance < 0) return PlaneSide.BACK; else return PlaneSide.FRONT; }
public boolean isFrontFacing(Vector3 direction) { double dot = Vector3.dot(mNormal, direction); return dot <= 0; }
public double getDistanceTo(Vector3 point) { return mD + mNormal.dot(point); }
/** * Calculates the angle between this {@link Vector3} and the provided {@link Vector3}. * * @param v {@link Vector3} The {@link Vector3} The {@link Vector3} to calculate the angle to. * * @return {@code double} The calculated angle, in degrees. */ public double angle(@NonNull Vector3 v) { double dot = dot(v); dot /= (length() * v.length()); return Math.toDegrees(Math.acos(dot)); }
/** * Projects the specified {@link Vector3} onto this one and sets this {@link Vector3} * to the result. * * @param v {@link Vector3} to be projected. * * @return A reference to this {@link Vector3} to facilitate chaining. */ @NonNull public Vector3 project(@NonNull Vector3 v) { double d = dot(v); double d_div = d / length2(); return multiply(d_div); }
/** * Projects {@link Vector3} u onto {@link Vector3} v and creates a new * {@link Vector3} for the result. * * @param u {@link Vector3} to be projected. * @param v {@link Vector3} the {@link Vector3} to be projected on. * * @return {@link Vector3} The result of the projection. */ @NonNull public static Vector3 projectAndCreate(@NonNull Vector3 u, @NonNull Vector3 v) { double d = u.dot(v); double d_div = d / v.length2(); return v.clone().multiply(d_div); }
protected Quaternion quaternionFromVector(Vector3 vec) { vec.normalize(); final double angle = MathUtil.radiansToDegrees(Math.acos(Vector3.dot(mForwardVec, vec))); final Quaternion q = new Quaternion(); q.fromAngleAxis(mTmpQuatVector.crossAndSet(mForwardVec, vec), angle); return q; } }
@Test public void testDotFromTwoDoublesXyz() { final double dot = Vector3.dot(1d, 2d, 3d, 4d, 5d, 6d); assertEquals(32d, dot, 0); }
/** * Intersects a ray defined by a start and end point and a {@link Plane}. * @param rayStart Startpoint of the ray * @param rayEnd Endpoint of the ray * @param plane The plane * @param hitPoint The intersection point (optional) * @return True if there is an intersection, false otherwise. */ public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }
/** * Sets this {@link Quaternion} to be oriented to a target {@link Vector3}. * It is safe to use the input vectors for other things as they are cloned internally. * * @param lookAt {@link Vector3} The point to look at. * @param upDirection {@link Vector3} to use as the up direction. * * @return A reference to this {@link Quaternion} to facilitate chaining. */ @NonNull public Quaternion lookAt(@NonNull Vector3 lookAt, @NonNull Vector3 upDirection) { mTmpVec1.setAll(lookAt); mTmpVec2.setAll(upDirection); // Vectors are parallel/anti-parallel if their dot product magnitude and length product are equal final double dotProduct = Vector3.dot(lookAt, upDirection); final double dotError = Math.abs(Math.abs(dotProduct) - (lookAt.length() * upDirection.length())); if (dotError <= PARALLEL_TOLERANCE) { // The look and up vectors are parallel mTmpVec2.normalize(); if (dotProduct < 0) { mTmpVec1.inverse(); } fromRotationBetween(WorldParameters.FORWARD_AXIS, mTmpVec1); return this; } Vector3.orthoNormalize(mTmpVec1, mTmpVec2); // Find the forward and up vectors mTmpVec3.crossAndSet(mTmpVec2, mTmpVec1); // Create the right vector fromAxes(mTmpVec3, mTmpVec2, mTmpVec1); return this; }
public void set(Vector3 point1, Vector3 point2, Vector3 point3) { Vector3 v1 = new Vector3(); Vector3 v2 = new Vector3(); v1.subtractAndSet(point1, point2); v2.subtractAndSet(point3, point2); mNormal = v1.cross(v2); mNormal.normalize(); mD = -point1.dot(mNormal); }
final double dot = u.dot(v); final double dotError = 1.0 - Math.abs(MathUtil.clamp(dot, -1f, 1f)); if (dotError <= PARALLEL_TOLERANCE) {
@Test public void testDotFromDoublesXyz() { final Vector3 v = new Vector3(1d, 2d, 3d); final double dot = v.dot(4d, 5d, 6d); assertEquals(32d, dot, 0); }
@Test public void testDotFromTwoVector3() { final Vector3 v1 = new Vector3(1d, 2d, 3d); final Vector3 v2 = new Vector3(4d, 5d, 6d); final double dot = Vector3.dot(v1, v2); assertEquals(32d, dot, 0); }
@Test public void testDotFromVector3() { final Vector3 v = new Vector3(1d, 2d, 3d); final Vector3 v1 = new Vector3(4d, 5d, 6d); final double dot = v.dot(v1); assertEquals(32d, dot, 0); }
private void applyRotation() { if (mIsRotating) { mapToSphere((float) mPrevScreenCoord.getX(), (float) mPrevScreenCoord.getY(), mPrevSphereCoord); mapToSphere((float) mCurrScreenCoord.getX(), (float) mCurrScreenCoord.getY(), mCurrSphereCoord); Vector3 rotationAxis = mPrevSphereCoord.clone(); rotationAxis.cross(mCurrSphereCoord); rotationAxis.normalize(); double rotationAngle = Math.acos(Math.min(1, mPrevSphereCoord.dot(mCurrSphereCoord))); mCurrentOrientation.fromAngleAxis(rotationAxis, MathUtil.radiansToDegrees(rotationAngle)); mCurrentOrientation.normalize(); Quaternion q = new Quaternion(mStartOrientation); q.multiply(mCurrentOrientation); mEmpty.setOrientation(q); } }
double angleLightCamera = lightToCamDirection.dot(cameraDirection);
public PlaneSide getPointSide(Vector3 point) { double distance = Vector3.dot(mNormal, point) + mD; if (distance == 0) return PlaneSide.ONPLANE; else if (distance < 0) return PlaneSide.BACK; else return PlaneSide.FRONT; }