/** * Returns cos of a value. * * @param dValue * The value to cosine, in radians. * @return The cosine of dValue. * @see java.lang.Math#cos(double) */ public static double cos(final double dValue) { return sin(dValue + MathUtils.HALF_PI); }
/** * Returns cos of a value. * * @param dValue * The value to cosine, in radians. * @return The cosine of dValue. * @see java.lang.Math#cos(double) */ public static double cos(final double dValue) { return sin(dValue + MathUtils.HALF_PI); }
/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Internally rotates this vector around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @return this vector for chaining */ public Vector2 rotateAroundOriginLocal(double angle, final boolean clockwise) { if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return set(newX, newY); }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
/** * Creates a new vector representing this vector rotated around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return the new rotated vector */ @Override public Vector2 rotateAroundOrigin(double angle, final boolean clockwise, final Vector2 store) { Vector2 result = store; if (result == null) { result = new Vector2(); } if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return result.set(newX, newY); }
/** * Creates a new vector representing this vector rotated around 0,0 by a specified angle in a given direction. * * @param angle * in radians * @param clockwise * true to rotate in a clockwise direction * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return the new rotated vector */ @Override public Vector2 rotateAroundOrigin(double angle, final boolean clockwise, final Vector2 store) { Vector2 result = store; if (result == null) { result = new Vector2(); } if (clockwise) { angle = -angle; } final double newX = MathUtils.cos(angle) * getX() - MathUtils.sin(angle) * getY(); final double newY = MathUtils.sin(angle) * getX() + MathUtils.cos(angle) * getY(); return result.set(newX, newY); }
/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
/** * Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation. * If axis == 0,0,0 the quaternion is set to identity. * * @param angle * the angle to rotate (in radians). * @param axis * the axis of rotation (already normalized - unit length). * @throws NullPointerException * if axis is null */ public Quaternion fromAngleNormalAxis(final double angle, final ReadOnlyVector3 axis) { if (axis.equals(Vector3.ZERO)) { return setIdentity(); } final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double w = MathUtils.cos(halfAngle); final double x = sin * axis.getX(); final double y = sin * axis.getY(); final double z = sin * axis.getZ(); return set(x, y, z, w); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesianZ(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = a * sin(sphereCoords.getY()); final double z = sphereCoords.getX() * sin(sphereCoords.getZ()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesianZ(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = a * sin(sphereCoords.getY()); final double z = sphereCoords.getX() * sin(sphereCoords.getZ()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesian(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = sphereCoords.getX() * sin(sphereCoords.getZ()); final double z = a * sin(sphereCoords.getY()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the * store var. * * @param sphereCoords * (Radius, Azimuth, Polar) * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 sphericalToCartesian(final ReadOnlyVector3 sphereCoords, final Vector3 store) { final double a = sphereCoords.getX() * cos(sphereCoords.getZ()); final double x = a * cos(sphereCoords.getY()); final double y = sphereCoords.getX() * sin(sphereCoords.getZ()); final double z = a * sin(sphereCoords.getY()); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Apply rotation around Z * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationZ(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getY() * sin; final double newY = -getX() * sin + getY() * cos; final double newZ = getZ() * cos + getW() * sin; final double newW = -getZ() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Z * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationZ(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getY() * sin; final double newY = -getX() * sin + getY() * cos; final double newZ = getZ() * cos + getW() * sin; final double newW = -getZ() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Y * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationY(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos - getZ() * sin; final double newY = getY() * cos + getW() * sin; final double newZ = getX() * sin + getZ() * cos; final double newW = -getY() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around X * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationX(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getW() * sin; final double newY = getY() * cos + getZ() * sin; final double newZ = -getY() * sin + getZ() * cos; final double newW = -getX() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around X * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationX(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos + getW() * sin; final double newY = getY() * cos + getZ() * sin; final double newZ = -getY() * sin + getZ() * cos; final double newW = -getX() * sin + getW() * cos; return set(newX, newY, newZ, newW); }
/** * Apply rotation around Y * * @param angle * in radians * @return this quaternion for chaining. */ public Quaternion applyRotationY(final double angle) { final double halfAngle = 0.5 * angle; final double sin = MathUtils.sin(halfAngle); final double cos = MathUtils.cos(halfAngle); final double newX = getX() * cos - getZ() * sin; final double newY = getY() * cos + getW() * sin; final double newZ = getX() * sin + getZ() * cos; final double newW = -getY() * sin + getW() * cos; return set(newX, newY, newZ, newW); }