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