chickadee » quaternions

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.


Quaternions are an extension to the number system: real numbers may be thought of as points on a line, complex numbers as points in a plane, and quaternion numbers as points in four-dimensional space.

Apart from mathematical curiosity, quaternions are useful for specifying rotations in three dimensional space (e.g. in this game), and also for image analysis.

An introduction to quaternions and this scheme library is available here.

Exported Procedures

(make-rectangular w [x [y z]])procedure

Constructs a number, complex number, or quaternion number depending on if given 1, 2 or 4 arguments.

> (make-rectangular 1)
> (make-rectangular 1 2)
> (make-rectangular 1 2 3 4)
(make-polar mu theta [phi psi])procedure

An alternative way of defining a quaternion, through the magnitude mu, the angle theta, the colatitude phi and longitude psi.

real-part nprocedure

Returns the real part of a number.

> (real-part (make-rectangular 1 2 3 4))
imag-part nprocedure

Returns the imaginary part (the i) of a complex or quaternion number.

> (imag-part (make-rectangular 1 2 3 4))
jmag-part nprocedure

Returns the j part of a quaternion number.

> (jmag-part (make-rectangular 1 2 3 4))
kmag-part nprocedure

Returns the k part of a quaternion number.

> (kmag-part (make-rectangular 1 2 3 4))
magnitude nprocedure

The length of n treated as a vector.

angle nprocedure

See make-polar.

number? nprocedure

Checks if given argument is any kind of number.

> (number? 3)
> (number? 1+2i)
> (number? (make-rectangular 1 2 3 4))
quaternion? nprocedure

The same as number?.

= q1 ...procedure

Tests for equality of given numbers.

+ q1 ...procedure

Returns the sum of given numbers.

> (+ 3 2+3i (make-rectangular 1 2 3 4))
- q1 ...procedure

Returns the difference of given numbers, associating to left.

* q1 ...procedure

Returns the product of given numbers.

> (* 2 (make-rectangular 1 2 3 4))
/ q1 ...procedure

Returns quotient of given numbers, associating to left.

exp nprocedure

Usual exp function extended to quaternions.

log nprocedure

Usual log function extended to quaternions.

expt m nprocedure

Usual expt function extended to quaternions.

sqrt nprocedure

Usual sqrt function extended to quaternions.

sin nprocedure

Usual sin function extended to quaternions.

cos nprocedure

Usual cos function extended to quaternions.

tan nprocedure

Usual tan function extended to quaternions.

asin nprocedure

Usual asin function extended to quaternions.

acos nprocedure

Usual acos function extended to quaternions.

atan nprocedure

Usual atan function extended to quaternions.

atan y xprocedure

Usual atan function extended to quaternions.

vector-part qprocedure

Returns the quaternion with its real part set to 0.

colatitude qprocedure

See make-polar.

longitude qprocedure

See make-polar.

conjugate qprocedure

Returns quaternion with same real part and sign of i j and k part of q reversed.

> (conjugate (make-rectangular 1 2 3 4))
unit-vector qprocedure

Returns a quaternion in same direction as q but of unit length; the real part of q is set to 0.

dot-product q1 q2procedure

Real parts of q1 and q2 must be 0. The dot product is the negative of the real part of q1 x q2.

cross-product q1 q2procedure

Real parts of q1 and q2 must be 0. The cross product is the vector part of q1 x q2.


The original version of this library was created by Dorai Sitaram.

This port to chicken scheme is by Peter Lane.


GPL version 3.0.

Version History

Contents »