public double angleBetween(final TouchHistory other) { final double dx = other.currX - currX; final double dy = other.currY - currY; double angle; // avoid divide by 0 if (Math.abs(dx) < 0.001) { final double h = MathUtils.sqrt(dx * dx + dy * dy); angle = (h < 0.001) ? 0 : MathUtils.asin(dy / h); } else { angle = Math.atan2(dy, dx); } angle = angle < 0 ? angle + MathUtils.TWO_PI : angle; return angle; } }
/** * 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); }
/** * 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); }