You are looking at historical revision 21661 of this page. It may differ significantly from its current revision.

## Quaternions

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

*[procedure]*

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

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

> (make-rectangular 1) 1 > (make-rectangular 1 2) 1+2i > (make-rectangular 1 2 3 4) 1+2i+3j+4k

*[procedure]*

`(make-polar )`

*[procedure]*

`(real-part n)`

Returns the real part of a number.

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

*[procedure]*

`(imag-part n)`

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

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

*[procedure]*

`(jmag-part n)`

Returns the `j` part of a quaternion number.

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

*[procedure]*

`(kmag-part n)`

Returns the `k` part of a quaternion number.

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

*[procedure]*

`(magnitude )`

*[procedure]*

`(angle )`

*[procedure]*

`(number? n)`

Checks if given argument is any kind of number.

> (number? 3) #t > (number? 1+2i) #t > (number? (make-rectangular 1 2 3 4)) #t

*[procedure]*

`(quaternion? n)`

The same as `number?`.

*[procedure]*

`(= q1 ...)`

Tests for equality of given numbers.

*[procedure]*

`(+ q1 ...)`

Returns the sum of given numbers.

> (+ 3 2+3i (make-rectangular 1 2 3 4)) 6+5i+3j+4k

*[procedure]*

`(- q1 ...)`

Returns the difference of given numbers, associating to left.

*[procedure]*

`(* q1 ...)`

Returns the product of given numbers.

> (* 2 (make-rectangular 1 2 3 4)) 2+4i+6j+8k

*[procedure]*

`(/ q1 ...)`

Returns quotient of given numbers, associating to left.

*[procedure]*

`(exp )`

*[procedure]*

`(log )`

*[procedure]*

`(expt )`

*[procedure]*

`(sqrt )`

*[procedure]*

`(sin )`

*[procedure]*

`(cos )`

*[procedure]*

`(tan )`

*[procedure]*

`(asin )`

*[procedure]*

`(acos )`

*[procedure]*

`(atan )`

*[procedure]*

`(vector-part )`

*[procedure]*

`(colatitude )`

*[procedure]*

`(longitude )`

*[procedure]*

`(conjugate )`

*[procedure]*

`(unit-vector )`

*[procedure]*

`(dot-product )`

*[procedure]*

`(cross-product )`

### Author

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

This port to chicken scheme is by Peter Lane.

### License

GPL version 3.0.

### Version History

in progress.