/** * @return the magnitude or distance between the origin (0, 0, 0) and the point described by this vector (x, y, z). * Effectively the square root of the value returned by {@link #lengthSquared()}. */ @Override public double length() { return MathUtils.sqrt(lengthSquared()); }
/** * @return the magnitude or distance between the origin (0, 0, 0) and the point described by this vector (x, y, z). * Effectively the square root of the value returned by {@link #lengthSquared()}. */ @Override public double length() { return MathUtils.sqrt(lengthSquared()); }
/** * Converts this vector into a unit vector by dividing it internally by its length. If the length is 0, (ie, if the * vector is 0, 0, 0) then no action is taken. * * @return this vector for chaining */ public Vector3 normalizeLocal() { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiplyLocal(MathUtils.inverseSqrt(lengthSq)); } return this; }
/** * Converts this vector into a unit vector by dividing it internally by its length. If the length is 0, (ie, if the * vector is 0, 0, 0) then no action is taken. * * @return this vector for chaining */ public Vector3 normalizeLocal() { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiplyLocal(MathUtils.inverseSqrt(lengthSq)); } return this; }
/** * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, if the vector is * 0, 0, 0) then a new vector (0, 0, 0) is returned. * * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return a new unit vector (or 0, 0, 0 if this unit is 0 length) */ @Override public Vector3 normalize(final Vector3 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector3.ZERO) : new Vector3(Vector3.ZERO); }
/** * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, if the vector is * 0, 0, 0) then a new vector (0, 0, 0) is returned. * * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return a new unit vector (or 0, 0, 0 if this unit is 0 length) */ @Override public Vector3 normalize(final Vector3 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector3.ZERO) : new Vector3(Vector3.ZERO); }
/** * <code>averagePoints</code> selects the sphere center to be the average of the points and the sphere radius to be * the smallest value to enclose all points. * * @param points * the list of points to contain. */ public void averagePoints(final Vector3[] points) { _center.set(points[0]); for (int i = 1; i < points.length; i++) { _center.addLocal(points[i]); } final double quantity = 1.0 / points.length; _center.multiplyLocal(quantity); double maxRadiusSqr = 0; for (int i = 0; i < points.length; i++) { final Vector3 diff = points[i].subtract(_center, _compVect1); final double radiusSqr = diff.lengthSquared(); if (radiusSqr > maxRadiusSqr) { maxRadiusSqr = radiusSqr; } } setRadius(Math.sqrt(maxRadiusSqr) + radiusEpsilon - 1f); }
/** * <code>averagePoints</code> selects the sphere center to be the average of the points and the sphere radius to be * the smallest value to enclose all points. * * @param points * the list of points to contain. */ public void averagePoints(final Vector3[] points) { _center.set(points[0]); for (int i = 1; i < points.length; i++) { _center.addLocal(points[i]); } final double quantity = 1.0 / points.length; _center.multiplyLocal(quantity); double maxRadiusSqr = 0; for (int i = 0; i < points.length; i++) { final Vector3 diff = points[i].subtract(_center, _compVect1); final double radiusSqr = diff.lengthSquared(); if (radiusSqr > maxRadiusSqr) { maxRadiusSqr = radiusSqr; } } setRadius(Math.sqrt(maxRadiusSqr) + radiusEpsilon - 1f); }
/** * Calculates the minimum bounding sphere of 3 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 acrossB = a.cross(b, null); final double Denominator = 2.0 * acrossB.dot(acrossB); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared()) .addLocal(b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
final double distSq = vec.lengthSquared(); if (distSq < _innerRadius * _innerRadius) { return _center;
/** * Calculates the minimum bounding sphere of 3 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 acrossB = a.cross(b, null); final double Denominator = 2.0 * acrossB.dot(acrossB); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared()) .addLocal(b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
/** * @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; }
/** * @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; }
/** * Calculates the minimum bounding sphere of 4 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @param C * The 4th point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B, final Vector3 C) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 c = C.subtract(O, null); final double Denominator = 2.0 * (a.getX() * (b.getY() * c.getZ() - c.getY() * b.getZ()) - b.getX() * (a.getY() * c.getZ() - c.getY() * a.getZ()) + c.getX() * (a.getY() * b.getZ() - b.getY() * a.getZ())); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = a.cross(b, null).multiplyLocal(c.lengthSquared()) .addLocal(c.cross(a, null).multiplyLocal(b.lengthSquared())) .addLocal(b.cross(c, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
/** * @param point * @param store * if not null, the closest point is stored in this param * @return the squared distance from this ray to the given point. * @throws NullPointerException * if the point is null. */ @Override public double distanceSquared(final ReadOnlyVector3 point, final Vector3 store) { final Vector3 vectorA = Vector3.fetchTempInstance(); vectorA.set(point).subtractLocal(_origin); final double t0 = _direction.dot(vectorA); if (t0 > 0) { // d = |P - (O + t*D)| vectorA.set(_direction).multiplyLocal(t0); vectorA.addLocal(_origin); } else { // ray is closest to origin point vectorA.set(_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; }
/** * @param point * @param store * if not null, the closest point is stored in this param * @return the squared distance from this ray to the given point. * @throws NullPointerException * if the point is null. */ @Override public double distanceSquared(final ReadOnlyVector3 point, final Vector3 store) { final Vector3 vectorA = Vector3.fetchTempInstance(); vectorA.set(point).subtractLocal(_origin); final double t0 = _direction.dot(vectorA); if (t0 > 0) { // d = |P - (O + t*D)| vectorA.set(_direction).multiplyLocal(t0); vectorA.addLocal(_origin); } else { // ray is closest to origin point vectorA.set(_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; }
/** * Calculates the minimum bounding sphere of 4 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @param C * The 4th point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B, final Vector3 C) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 c = C.subtract(O, null); final double Denominator = 2.0 * (a.getX() * (b.getY() * c.getZ() - c.getY() * b.getZ()) - b.getX() * (a.getY() * c.getZ() - c.getY() * a.getZ()) + c.getX() * (a.getY() * b.getZ() - b.getY() * a.getZ())); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = a.cross(b, null).multiplyLocal(c.lengthSquared()) .addLocal(c.cross(a, null).multiplyLocal(b.lengthSquared())) .addLocal(b.cross(c, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
if (b1.lengthSquared() < MathUtils.EPSILON) { _up.cross(Vector3.UNIT_Y, b1);
if (b1.lengthSquared() < MathUtils.EPSILON) { _up.cross(Vector3.UNIT_Y, b1);
final double lSQ = vectorA.lengthSquared(); Vector3.releaseTempInstance(vectorA); return lSQ;