Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Quaternion rules]
- i² = j² = k² = i*j*k = -1
- i*j = k j*i = -k
- j*k = i k*j = -i
- k*i = j i*k = -j
- [Example quaternion "q" and point "p"]
- q(x,y,z,w) = q.w + q.x*i + q.y*j + q.z*k
- q'(x,y,z,w) = q.w - q.x*i - q.y*j - q.z*k
- p(x,y,z) = p.x*i + p.y*j + p.z*k
- p' = q * p * q'
- p' = (q.w + q.x*i + q.y*j + q.z*k) * (p.x*i + p.y*j + p.z*k) * (q.w - q.x*i - q.y*j - q.z*k)
- // first and second bracket combined
- p' = (
- q.w*p.x*i + q.x*i*p.x*i + q.y*j*p.x*i + q.z*k*p.x*i +
- q.w*p.y*j + q.x*i*p.y*j + q.y*j*p.y*j + q.z*k*p.y*j +
- q.w*p.z*k + q.x*i*p.z*k + q.y*j*p.z*k + q.z*k*p.z*k
- ) * (q.w - q.x*i - q.y*j - q.z*k)
- // all brackets combined
- p' = (
- q.w*p.x*i*q.w + q.x*i*p.x*i*q.w + q.y*j*p.x*i*q.w + q.z*k*p.x*i*q.w +
- q.w*p.y*j*q.w + q.x*i*p.y*j*q.w + q.y*j*p.y*j*q.w + q.z*k*p.y*j*q.w +
- q.w*p.z*k*q.w + q.x*i*p.z*k*q.w + q.y*j*p.z*k*q.w + q.z*k*p.z*k*q.w +
- q.w*p.x*i*(-q.x*i) + q.x*i*p.x*i*(-q.x*i) + q.y*j*p.x*i*(-q.x*i) + q.z*k*p.x*i*(-q.x*i) +
- q.w*p.y*j*(-q.x*i) + q.x*i*p.y*j*(-q.x*i) + q.y*j*p.y*j*(-q.x*i) + q.z*k*p.y*j*(-q.x*i) +
- q.w*p.z*k*(-q.x*i) + q.x*i*p.z*k*(-q.x*i) + q.y*j*p.z*k*(-q.x*i) + q.z*k*p.z*k*(-q.x*i) +
- q.w*p.x*i*(-q.y*j) + q.x*i*p.x*i*(-q.y*j) + q.y*j*p.x*i*(-q.y*j) + q.z*k*p.x*i*(-q.y*j) +
- q.w*p.y*j*(-q.y*j) + q.x*i*p.y*j*(-q.y*j) + q.y*j*p.y*j*(-q.y*j) + q.z*k*p.y*j*(-q.y*j) +
- q.w*p.z*k*(-q.y*j) + q.x*i*p.z*k*(-q.y*j) + q.y*j*p.z*k*(-q.y*j) + q.z*k*p.z*k*(-q.y*j) +
- q.w*p.x*i*(-q.z*k) + q.x*i*p.x*i*(-q.z*k) + q.y*j*p.x*i*(-q.z*k) + q.z*k*p.x*i*(-q.z*k) +
- q.w*p.y*j*(-q.z*k) + q.x*i*p.y*j*(-q.z*k) + q.y*j*p.y*j*(-q.z*k) + q.z*k*p.y*j*(-q.z*k) +
- q.w*p.z*k*(-q.z*k) + q.x*i*p.z*k*(-q.z*k) + q.y*j*p.z*k*(-q.z*k) + q.z*k*p.z*k*(-q.z*k)
- )
- // applying multiplication rules from above
- p' = (
- q.w*p.x*q.w*i - q.x*p.x*q.w - q.y*p.x*q.w*k + q.z*p.x*q.w*j
- +q.w*p.y*q.w*j + q.x*p.y*q.w*k - q.y*p.y*q.w - q.z*p.y*q.w*i
- +q.w*p.z*q.w*k - q.x*p.z*q.w*j + q.y*p.z*q.w*i - q.z*p.z*q.w
- +q.w*p.x*q.x + q.x*p.x*q.x*i + q.y*p.x*q.x*j + q.z*p.x*q.x*k
- +q.w*p.y*q.x*k - q.x*p.y*q.x*j + q.y*p.y*q.x*i - q.z*p.y*q.x
- -q.w*p.z*q.x*j - q.x*p.z*q.x*k + q.y*p.z*q.x + q.z*p.z*q.x*i
- -q.w*p.x*q.y*k + q.x*p.x*q.y*j - q.y*p.x*q.y*i + q.z*p.x*q.y
- +q.w*p.y*q.y + q.x*p.y*q.y*i + q.y*p.y*q.y*j + q.z*p.y*q.y*k
- +q.w*p.z*q.y*i - q.x*p.z*q.y - q.y*p.z*q.y*k + q.z*p.z*q.y*j
- +q.w*p.x*q.z*j + q.x*p.x*q.z*k - q.y*p.x*q.z - q.z*p.x*q.z*i
- -q.w*p.y*q.z*i + q.x*p.y*q.z + q.y*p.y*q.z*k - q.z*p.y*q.z*j
- +q.w*p.z*q.z + q.x*p.z*q.z*i + q.y*p.z*q.z*j + q.z*p.z*q.z*k
- )
- // regroup according to imaginary units:
- p' = (
- - q.x*p.x*q.w - q.y*p.y*q.w - q.z*p.z*q.w + q.w*p.x*q.x - q.z*p.y*q.x + q.y*p.z*q.x + q.z*p.x*q.y + q.w*p.y*q.y - q.x*p.z*q.y - q.y*p.x*q.z + q.x*p.y*q.z + q.w*p.z*q.z
- + q.w*p.x*q.w*i - q.z*p.y*q.w*i + q.y*p.z*q.w*i + q.x*p.x*q.x*i + q.y*p.y*q.x*i + q.z*p.z*q.x*i - q.y*p.x*q.y*i + q.x*p.y*q.y*i + q.w*p.z*q.y*i - q.z*p.x*q.z*i - q.w*p.y*q.z*i + q.x*p.z*q.z*i
- + q.z*p.x*q.w*j + q.w*p.y*q.w*j - q.x*p.z*q.w*j + q.y*p.x*q.x*j - q.x*p.y*q.x*j - q.w*p.z*q.x*j + q.x*p.x*q.y*j + q.y*p.y*q.y*j + q.z*p.z*q.y*j + q.w*p.x*q.z*j - q.z*p.y*q.z*j + q.y*p.z*q.z*j
- - q.y*p.x*q.w*k + q.x*p.y*q.w*k + q.w*p.z*q.w*k + q.z*p.x*q.x*k + q.w*p.y*q.x*k - q.x*p.z*q.x*k - q.w*p.x*q.y*k + q.z*p.y*q.y*k - q.y*p.z*q.y*k + q.x*p.x*q.z*k + q.y*p.y*q.z*k + q.z*p.z*q.z*k
- )
- // factor out the imaginary units
- p' = (
- (- q.x*p.x*q.w + q.w*p.x*q.x - q.y*p.y*q.w + q.w*p.y*q.y - q.z*p.z*q.w + q.w*p.z*q.z - q.z*p.y*q.x+ q.x*p.y*q.z + q.y*p.z*q.x - q.x*p.z*q.y + q.z*p.x*q.y - q.y*p.x*q.z )+
- (+ q.w*p.x*q.w - q.z*p.y*q.w + q.y*p.z*q.w + q.x*p.x*q.x + q.y*p.y*q.x + q.z*p.z*q.x - q.y*p.x*q.y + q.x*p.y*q.y + q.w*p.z*q.y - q.z*p.x*q.z - q.w*p.y*q.z + q.x*p.z*q.z)*i+
- (+ q.z*p.x*q.w + q.w*p.y*q.w - q.x*p.z*q.w + q.y*p.x*q.x - q.x*p.y*q.x - q.w*p.z*q.x + q.x*p.x*q.y + q.y*p.y*q.y + q.z*p.z*q.y + q.w*p.x*q.z - q.z*p.y*q.z + q.y*p.z*q.z)*j+
- (- q.y*p.x*q.w + q.x*p.y*q.w + q.w*p.z*q.w + q.z*p.x*q.x + q.w*p.y*q.x - q.x*p.z*q.x - q.w*p.x*q.y + q.z*p.y*q.y - q.y*p.z*q.y + q.x*p.x*q.z + q.y*p.y*q.z + q.z*p.z*q.z)*k
- )
- // eliminate real part and group terms after p.x, p.y and p.z
- p' = (
- (0 )+
- (+ q.w*q.w*p.x + q.x*q.x*p.x - q.y*q.y*p.x - q.z*q.z*p.x - q.z*q.w*p.y + q.x*q.y*p.y + q.x*q.y*p.y - q.z*q.w*p.y + q.y*q.w*p.z + q.x*q.z*p.z + q.y*q.w*p.z + q.x*q.z*p.z)*i+
- (+ q.z*q.w*p.x + q.y*q.x*p.x + q.w*q.z*p.x + q.x*q.y*p.x + q.w*q.w*p.y - q.x*q.x*p.y - q.z*q.z*p.y + q.y*q.y*p.y + q.z*q.y*p.z + q.y*q.z*p.z - q.x*q.w*p.z - q.w*q.x*p.z)*j+
- (+ q.z*q.x*p.x - q.y*q.w*p.x + q.x*q.z*p.x - q.w*q.y*p.x + q.x*q.w*p.y + q.y*q.z*p.y + q.w*q.x*p.y + q.z*q.y*p.y - q.y*q.y*p.z + q.z*q.z*p.z + q.w*q.w*p.z - q.x*q.x*p.z)*k
- )
- // factor out p.x,p.y and p.z
- p' = (
- (0 )+
- (+ (q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z)*p.x + (q.x*q.y + q.x*q.y - q.z*q.w - q.z*q.w)*p.y + (q.y*q.w + q.y*q.w + q.x*q.z + q.x*q.z)*p.z)*i+
- (+ (q.z*q.w + q.y*q.x + q.w*q.z + q.x*q.y)*p.x + (q.w*q.w - q.x*q.x - q.z*q.z + q.y*q.y)*p.y + (q.z*q.y + q.y*q.z - q.x*q.w - q.w*q.x)*p.z)*j+
- (+ (q.z*q.x - q.y*q.w + q.x*q.z - q.w*q.y)*p.x + (q.x*q.w + q.y*q.z + q.w*q.x + q.z*q.y)*p.y - (q.y*q.y + q.z*q.z + q.w*q.w - q.x*q.x)*p.z)*k
- )
- // simplify
- p' = (
- (0 )+
- (+ (q.w*q.w+q.x*q.x-q.y*q.y-q.z*q.z)*p.x + (2*q.x*q.y - 2* q.z*q.w ) *p.y + (2*q.y*q.w + 2*q.x*q.z) *p.z)*i+
- (+ (2*q.z*q.w +2*q.x*q.y) *p.x + (q.w*q.w-q.x*q.x-q.z*q.z+q.y*q.y)*p.y + (2*q.z*q.y - 2*q.x*q.w) *p.z)*j+
- (+ (2*q.z*q.x - 2*q.y*q.w) *p.x + (2*q.x*q.w + 2*q.y*q.z) *p.y - (q.y*q.y+q.z*q.z+q.w*q.w-q.x*q.x)*p.z)*k
- )
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement