Squeak Class Documentation category index | class index  
 
B3DRotation
  category: Balloon3D-Vectors
  superclass: B3DFloatArray
  subclasses:

I represent general 3d rotations by using Unit-Quaternions. Unit-Quaternions are one of the best available representation for rotations in computer graphics because they provide an easy way of doing arithmetic with them and also because they allow us to use spherical linear interpolation (so-called "slerps") of rotations.

Indexed Variables:
a <Float> the real part of the quaternion
b <Float> the first imaginary part of the quaternion
c <Float> the second imaginary part of the quaternion
d <Float> the third imaginary part of the quaternion

instance methods
  accessing
  a
a:
angle
angle:
axis
axis:
b
b:
c
c:
d
d:

  arithmetic
  *
negated
normalize

  converting
  asMatrix4x4
normalized

  initialize
  a:b:c:d:
angle:axis:
from:to:
radiansAngle:axis:
setIdentity
x:y:z:a:

  interpolating
  interpolateTo:at:
slerpTo:at:
slerpTo:at:extraSpins:

  printing
  printOn:

  private
  bcd
matrixClass

class methods
  class initialization
  initialize

  instance creation
  a:b:c:d:
angle:axis:
axis:angle:
from:to:
identity
numElements
radiansAngle:axis:
x:y:z:a:

instance methods
  accessing top  
 

a


 

a:


 

angle


 

angle:


 

axis


 

axis:


 

b


 

b:


 

c


 

c:


 

d


 

d:


  arithmetic top  
 

*

Multiplying two rotations is the same as concatenating the two rotations.


 

negated

Negating a quaternion is the same as reversing the angle of rotation


 

normalize

Normalize the receiver. Note that the actual angle (a) determining the amount of
rotation is fixed, since we do not want to modify angles. This leads to:
a^2 + b^2 + c^2 + d^2 = 1.
b^2 + c^2 + d^2 = 1 - a^2.
Note also that the angle (a) can not exceed 1.0 (due its creation by cosine) and
if it is 1.0 we have exactly the unit quaternion ( 1, [ 0, 0, 0]).


  converting top  
 

asMatrix4x4

Given a quaternion q = (a, [ b, c , d]) the rotation matrix can be calculated as
| 1 - 2(cc+dd), 2(bc-da), 2(db+ca) |
m = | 2(bc+da), 1 - 2(bb+dd), 2(cd-ba) |
| 2(db-ca), 2(cd+ba), 1 - 2(bb+cc) |


 

normalized


  initialize top  
 

a:b:c:d:


 

angle:axis:


 

from:to:

Create a rotation from startVector to endVector


 

radiansAngle:axis:


 

setIdentity


 

x:y:z:a:


  interpolating top  
 

interpolateTo:at:

Spherical linear interpolation (slerp) from the receiver to aQuaternion


 

slerpTo:at:

Spherical linear interpolation (slerp) from the receiver to aQuaternion


 

slerpTo:at:extraSpins:

Sperical Linear Interpolation (slerp).
Calculate the new quaternion when applying slerp from the receiver (t = 0.0)
to aRotation (t = 1.0). spin indicates the number of extra rotations to be added.
The code shown below is from Graphics Gems III


  printing top  
 

printOn:

Append a sequence of characters that identify the receiver to aStream.


  private top  
 

bcd


 

matrixClass


class methods
  class initialization top  
 

initialize

B3DRotation initialize


  instance creation top  
 

a:b:c:d:


 

angle:axis:


 

axis:angle:


 

from:to:


 

identity


 

numElements


 

radiansAngle:axis:


 

x:y:z:a: