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
vecA andvecbare elementwise withinepsilonof each other.epsilondefaults to+default-epsilon+.
Cross product of
3dvector A and3dvectorb, return result as a freshly allocatedvec.
Compute hadamard product (elementwise product) of
vecA andvecb, return result as a freshly allocatedvec.
Linear interpolate
vecA andvecbusing single-floatfas the interpolation factor, return result as a freshly allocatedvec.
Elementwise maximum of
vecandvecs, return result as a freshly allocatedvec.
Elementwise minimum of
vecandvecs, return result as a freshly allocatedvec.
Multiply
vecdirectionby single-floatdistanceadding the result tovecpoint. Return result as a freshly allocatedvec.
Transform the axis-aligned bounding box specified by its extreme corners
v1andv2usingmatrix. Return new extreme corners (minimum and maximum coordinates) as freshly allocted VECs, as the primary and secondary value.
Apply transformation
matrixtovecignoring the translation component, return result as a freshly allocatedvec.
Apply transformation
matrixtovec, return result as a freshly allocatedvec.
Substract
vecbfromvecA, store result invecresult. Returnresult. Unsafe.
Multiply
vecA with single-floatf, store result invecresult. Returnresult. Unsafe.
Divide
vecA by single-floatf, store result invecresult. Returnresult. Unsafe.
Normalize
vecA, store result intovecresult. Returnresult. Unsafe.
Compute hadamard product (elementwise product) of
vecA andvecb, store result invecresult. Returnresult. Unsafe.
Linear interpolate
vecA andvecbusing single-floatfas the interpolation factor, store result invecresult. Returnresult. Unsafe.
Multiply
vecdirectionby single-floatdistanceadding the result tovecpoint. Store result inresult, and return it.
Apply transformation
matrixtovec, store result inresult. Returnresult. Unsafe.
Apply transformation
matrixtovec, 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
matrixwith the given elements (arguments are provided in row major order.)
Construct a rotation matrix that rotates by
radiansaroundvecv. 4th element ofvis ignored.
Construct a rotation matrix using first three elements of
vecas the rotation factors.
Construct a scaling matrix using first threee elements of
vecas the scaling factors.
Construct a translation matrix using first three elements of
vecas the translation factors.
Return true if
matrixm1andmatrixm2are elementwise withinepsilonof each other.epsilondefaults 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
limitfor Ax^3+Bx^2+Cx+D. Smallest positive root is returned as primary value, and others in increasing order.limitindicates 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
limitfor Ax^2+Bx+C. Smallest positive root is returned as primary value, and the other as secondary.limitindicates 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.