/** * Converts a point from Cartesian coordinates (using positive Y as up) to Spherical and stores the results in the * store var. (Radius, Azimuth, Polar) * * @param cartCoords * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 cartesianToSpherical(final ReadOnlyVector3 cartCoords, final Vector3 store) { final double cartX = Math.abs(cartCoords.getX()) <= MathUtils.EPSILON ? MathUtils.EPSILON : cartCoords.getX(); final double cartY = cartCoords.getY(); final double cartZ = cartCoords.getZ(); final double x = sqrt(cartX * cartX + cartY * cartY + cartZ * cartZ); final double y = atan(cartZ / cartX) + (cartX < 0.0 ? MathUtils.PI : 0); final double z = asin(cartY / x); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores the results in the * store var. (Radius, Azimuth, Polar) * * @param cartCoords * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 cartesianZToSpherical(final ReadOnlyVector3 cartCoords, final Vector3 store) { final double cartX = Math.abs(cartCoords.getX()) <= MathUtils.EPSILON ? MathUtils.EPSILON : cartCoords.getX(); final double cartY = cartCoords.getY(); final double cartZ = cartCoords.getZ(); final double x = sqrt(cartX * cartX + cartY * cartY + cartZ * cartZ); final double y = asin(cartY / x); final double z = atan(cartZ / cartX) + (cartX < 0.0 ? MathUtils.PI : 0); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores the results in the * store var. (Radius, Azimuth, Polar) * * @param cartCoords * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 cartesianZToSpherical(final ReadOnlyVector3 cartCoords, final Vector3 store) { final double cartX = Math.abs(cartCoords.getX()) <= MathUtils.EPSILON ? MathUtils.EPSILON : cartCoords.getX(); final double cartY = cartCoords.getY(); final double cartZ = cartCoords.getZ(); final double x = sqrt(cartX * cartX + cartY * cartY + cartZ * cartZ); final double y = asin(cartY / x); final double z = atan(cartZ / cartX) + (cartX < 0.0 ? MathUtils.PI : 0); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }
/** * Converts a point from Cartesian coordinates (using positive Y as up) to Spherical and stores the results in the * store var. (Radius, Azimuth, Polar) * * @param cartCoords * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. */ public static Vector3 cartesianToSpherical(final ReadOnlyVector3 cartCoords, final Vector3 store) { final double cartX = Math.abs(cartCoords.getX()) <= MathUtils.EPSILON ? MathUtils.EPSILON : cartCoords.getX(); final double cartY = cartCoords.getY(); final double cartZ = cartCoords.getZ(); final double x = sqrt(cartX * cartX + cartY * cartY + cartZ * cartZ); final double y = atan(cartZ / cartX) + (cartX < 0.0 ? MathUtils.PI : 0); final double z = asin(cartY / x); Vector3 rVal = store; if (rVal == null) { rVal = new Vector3(); } return rVal.set(x, y, z); }