SB-CGA is maintained in Git:
git clone git://github.com/nikodemus/sb-cga.git
will get you a local copy.
http://github.com/nikodemus/sb-cga
is the GitHub project page.
This documentation – and SB-CGA itself – is still a work in progress.
Most vector operations are done using special-purpose SSE2 primitives on SBCL/x86-64, and portable Common Lisp elsewhere.
Vector interface consists of two parts. The high-level interface always returns a freshly consed vector, whereas the low-level interface expects a new vector to store its results into.
Low level interface also implicitly trusts that argument counts and types are correct – bad things are liable to happen if those assumptions are violated, whereas the high-level operations should signal reasonable errors in such situations.
The system is fairly good about combining nested high-level operations
into low-level ones with minimal consing, and given proper
dynamic-extent
declarations can also stack allocate results of
vector operations on SBCL at least – including intermediate results.
User code should primarily use the high-level interface, and dip into the low level code only when absolutely necessary for performance.
Return true if
vec
A andvec
b
are elementwise withinepsilon
of each other.epsilon
defaults to+default-epsilon+
.
Cross product of
3d
vector A and3d
vectorb
, return result as a freshly allocatedvec
.
Compute hadamard product (elementwise product) of
vec
A andvec
b
, return result as a freshly allocatedvec
.
Linear interpolate
vec
A andvec
b
using single-floatf
as the interpolation factor, return result as a freshly allocatedvec
.
Elementwise maximum of
vec
andvecs
, return result as a freshly allocatedvec
.
Elementwise minimum of
vec
andvecs
, return result as a freshly allocatedvec
.
Multiply
vec
direction
by single-floatdistance
adding the result tovec
point
. Return result as a freshly allocatedvec
.
Transform the axis-aligned bounding box specified by its extreme corners
v1
andv2
usingmatrix
. Return new extreme corners (minimum and maximum coordinates) as freshly allocted VECs, as the primary and secondary value.
Apply transformation
matrix
tovec
ignoring the translation component, return result as a freshly allocatedvec
.
Apply transformation
matrix
tovec
, return result as a freshly allocatedvec
.
Substract
vec
b
fromvec
A, store result invec
result
. Returnresult
. Unsafe.
Multiply
vec
A with single-floatf
, store result invec
result
. Returnresult
. Unsafe.
Divide
vec
A by single-floatf
, store result invec
result
. Returnresult
. Unsafe.
Normalize
vec
A, store result intovec
result
. Returnresult
. Unsafe.
Compute hadamard product (elementwise product) of
vec
A andvec
b
, store result invec
result
. Returnresult
. Unsafe.
Linear interpolate
vec
A andvec
b
using single-floatf
as the interpolation factor, store result invec
result
. Returnresult
. Unsafe.
Multiply
vec
direction
by single-floatdistance
adding the result tovec
point
. Store result inresult
, and return it.
Apply transformation
matrix
tovec
, store result inresult
. Returnresult
. Unsafe.
Apply transformation
matrix
tovec
, store result inresult
. Returnresult
. Unsafe.
Transforming vectors using matrices as discussed above uses special purpose SSE2 primitives on SBCL/x86-64, and portable Common Lisp elsewhere.
Matrix algebra has otherwise not been specifically optimized, but should be reasoanably performant for the most part. If you find it substandard for your needs, let us know.
4x4 matrix of single floats, represented as a one-dimensional vector stored in column-major order.
Construct
matrix
with the given elements (arguments are provided in row major order.)
Construct a rotation matrix that rotates by
radians
aroundvec
v
. 4th element ofv
is ignored.
Construct a rotation matrix using first three elements of
vec
as the rotation factors.
Construct a scaling matrix using first threee elements of
vec
as the scaling factors.
Construct a translation matrix using first three elements of
vec
as the translation factors.
Return true if
matrix
m1
andmatrix
m2
are elementwise withinepsilon
of each other.epsilon
defaults to+default-epsilon+
Multiply
matrices
. The result might not be freshly allocated if all, or all but one multiplicant is an identity matrix.
Interface described here is liable to be refactored. See new-roots.lisp in the sources for the possible shape of things to come.
Real-valued roots greater than
limit
for Ax^3+Bx^2+Cx+D. Smallest positive root is returned as primary value, and others in increasing order.limit
indicates lack of a real-valued root abovelimit
.
Real-valued roots for Ax^2+Bx+C. Smallest real root is returned as primary value, and the others as the successive values. NaN indicates lack of a real-valued root.
Real-valued roots greater than
limit
for Ax^2+Bx+C. Smallest positive root is returned as primary value, and the other as secondary.limit
indicates lack of a real-valued root abovelimit
.
Real-valued roots for Ax^2+Bx+C. Smallest real root is returned as primary value, and the other as the secondary. In case of a double root both the primary and secondary values are the same. NaN indicates lack of a real-valued root.