/** * <code>getAngle</code> returns (in radians) the angle represented by * this Vector2f as expressed by a conversion from rectangular coordinates (<code>x</code>, <code>y</code>) * to polar coordinates (r, <i>theta</i>). * * @return the angle in radians. [-pi, pi) */ public float getAngle() { return FastMath.atan2(y, x); }
/** * <code>angleBetween</code> returns (in radians) the angle required to * rotate a ray represented by this vector to be colinear with a ray * described by the given vector. It is assumed that both this vector and * the given vector are unit vectors (iow, normalized). * * @param otherVector * the "destination" unit vector * @return the angle in radians. */ public float angleBetween(Vector2f otherVector) { float angle = FastMath.atan2(otherVector.y, otherVector.x) - FastMath.atan2(y, x); return angle; }
angles[1] = 2 * FastMath.atan2(x, w); angles[2] = FastMath.HALF_PI; angles[0] = 0; } else if (test < -0.499 * unit) { // singularity at south pole angles[1] = -2 * FastMath.atan2(x, w); angles[2] = -FastMath.HALF_PI; angles[0] = 0; } else { angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // yaw or heading angles[2] = FastMath.asin(2 * test / unit); // roll or bank angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // pitch or attitude
public static Quaternion stripToYaw(Quaternion q) { float yaw; float w = q.getW(); float x = q.getX(); float y = q.getY(); float z = q.getZ(); float sqx = x*x; float sqy = y*y; float sqz = z*z; float sqw = w*w; float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise // is correction factor float test = x * y + z * w; if (test > 0.499 * unit) { // singularity at north pole yaw = 2 * FastMath.atan2(x, w); } else if (test < -0.499 * unit) { // singularity at south pole yaw = -2 * FastMath.atan2(x, w); } else { yaw = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading } FastFullAngles(q, yaw, 0f, 0f); return q; } }
/** * <code>getAngle</code> returns (in radians) the angle represented by * this Vector2f as expressed by a conversion from rectangular coordinates (<code>x</code>, <code>y</code>) * to polar coordinates (r, <i>theta</i>). * * @return the angle in radians. [-pi, pi) */ public float getAngle() { return FastMath.atan2(y, x); }
/** * <code>getAngle</code> returns (in radians) the angle represented by * this Vector2f as expressed by a conversion from rectangular coordinates (<code>x</code>, <code>y</code>) * to polar coordinates (r, <i>theta</i>). * * @return the angle in radians. [-pi, pi) */ public float getAngle() { return FastMath.atan2(y, x); }
/** * <code>angleBetween</code> returns (in radians) the angle required to * rotate a ray represented by this vector to be colinear with a ray * described by the given vector. It is assumed that both this vector and * the given vector are unit vectors (iow, normalized). * * @param otherVector * the "destination" unit vector * @return the angle in radians. */ public float angleBetween(Vector2f otherVector) { float angle = FastMath.atan2(otherVector.y, otherVector.x) - FastMath.atan2(y, x); return angle; }
/** * <code>angleBetween</code> returns (in radians) the angle required to * rotate a ray represented by this vector to lie colinear to a ray * described by the given vector. It is assumed that both this vector and * the given vector are unit vectors (iow, normalized). * * @param otherVector * the "destination" unit vector * @return the angle in radians. */ public float angleBetween(Vector2f otherVector) { float angle = FastMath.atan2(otherVector.y, otherVector.x) - FastMath.atan2(y, x); return angle; }
angles[1] = 2 * FastMath.atan2(x, w); angles[2] = FastMath.HALF_PI; angles[0] = 0; } else if (test < -0.499 * unit) { // singularity at south pole angles[1] = -2 * FastMath.atan2(x, w); angles[2] = -FastMath.HALF_PI; angles[0] = 0; } else { angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // yaw or heading angles[2] = FastMath.asin(2 * test / unit); // roll or bank angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // pitch or attitude
angles[1] = 2 * FastMath.atan2(x, w); angles[2] = FastMath.HALF_PI; angles[0] = 0; } else if (test < -0.499 * unit) { // singularity at south pole angles[1] = -2 * FastMath.atan2(x, w); angles[2] = -FastMath.HALF_PI; angles[0] = 0; } else { angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading angles[2] = FastMath.asin(2 * test / unit); // pitch or attitude angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // yaw or bank