/** * Returns the polar form of the quaternion. * * @return the unit quaternion with positive scalar part. */ public Quaternion getPositivePolarForm() { if (getQ0() < 0) { final Quaternion unitQ = normalize(); // The quaternion of rotation (normalized quaternion) q and -q // are equivalent (i.e. represent the same rotation). return new Quaternion(-unitQ.getQ0(), -unitQ.getQ1(), -unitQ.getQ2(), -unitQ.getQ3()); } else { return this.normalize(); } }
public static Quaternion createQuaternion(int[] quat, double scale) { // This article suggests QUAT_W is [0] // https://github.com/vmayoral/bb_mpu9150/blob/master/src/linux-mpu9150/mpu9150/mpu9150.c Quaternion quaterion = new Quaternion(quat[MPU9150_QUAT_W]*scale, quat[MPU9150_QUAT_X]*scale, quat[MPU9150_QUAT_Y]*scale, quat[MPU9150_QUAT_Z]*scale); return quaterion.normalize(); }
/** * Returns the polar form of the quaternion. * * @return the unit quaternion with positive scalar part. */ public Quaternion getPositivePolarForm() { if (getQ0() < 0) { final Quaternion unitQ = normalize(); // The quaternion of rotation (normalized quaternion) q and -q // are equivalent (i.e. represent the same rotation). return new Quaternion(-unitQ.getQ0(), -unitQ.getQ1(), -unitQ.getQ2(), -unitQ.getQ3()); } else { return this.normalize(); } }
/** * Returns the polar form of the quaternion. * * @return the unit quaternion with positive scalar part. */ public Quaternion getPositivePolarForm() { if (getQ0() < 0) { final Quaternion unitQ = normalize(); // The quaternion of rotation (normalized quaternion) q and -q // are equivalent (i.e. represent the same rotation). return new Quaternion(-unitQ.getQ0(), -unitQ.getQ1(), -unitQ.getQ2(), -unitQ.getQ3()); } else { return this.normalize(); } }