/** * @return the magnitude or distance between the origin (0, 0, 0, 0) and the point described by this vector (x, y, * z, w). 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, 0) and the point described by this vector (x, y, * z, w). 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, 0) then no action is taken. * * @return this vector for chaining */ public Vector4 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, 0) then no action is taken. * * @return this vector for chaining */ public Vector4 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, 0) then a new vector (0, 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, 0 if this unit is 0 length) */ @Override public Vector4 normalize(final Vector4 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector4.ZERO) : new Vector4(Vector4.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, 0) then a new vector (0, 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, 0 if this unit is 0 length) */ @Override public Vector4 normalize(final Vector4 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector4.ZERO) : new Vector4(Vector4.ZERO); }