/** * Rotate a vector by the inverse of this quaternion. * * @param V the vector to be rotated * @return vector after rotation by the inverse of this quaternion. */ public FVector UnrotateVector(FVector V) { FVector Q = new FVector(-X, -Y, -Z); // Inverse FVector T = FVector.CrossProduct(Q, V) * 2.0f; FVector Result = V + (T * W) + FVector.CrossProduct(Q, T); return(Result); }
/** * Rotate a vector by this quaternion. * * @param V the vector to be rotated * @return vector after rotation */ public FVector RotateVector(FVector V) { // http://people.csail.mit.edu/bkph/articles/Quaternions.pdf // V' = V + 2w(Q x V) + (2Q x (Q x V)) // refactor: // V' = V + w(2(Q x V)) + (Q x (2(Q x V))) // T = 2(Q x V); // V' = V + w*(T) + (Q x T) FVector Q = new FVector(X, Y, Z); FVector T = FVector.CrossProduct(Q, V) * 2.0f; FVector Result = V + (T * W) + FVector.CrossProduct(Q, T); return(Result); }