3d vector math / basic linear algebra library

Memo Akten's icon

Hi all is there a 3d vector math / basic linear alegebra library for Max? Things I'd like to do is:

- convert an orientation (euler, quat or axis) to 3x3 rotation matrix and vice versa
- convert rotation, position, scale into 4x4 transformation matrix and vice versa
- transform 3d coordinates by a 4x4 transformation matrix (i.e matrix multiplication, for e.g. local to global coordinates)
- take inverse of a 4x4 transformation matrix (for e.g. global to local coordinates)
etc.

I know how to do it all from scratch and I've tried using jit.matrix but using a jit.matrix for a 3x1 list seems like a sledgehammer on a nail. Also I'm after an established solution which has a lot of features (like the countless c++ libs out there) not just a few things like rotation around an axis etc . Finally jit.expr syntax is absolutely horrid and cannot be taken seriously for something like this :)
https://twitter.com/memotv/status/585207451810672641

Also it would be ideal if I could do things like have a list of vertices in a jit.matrix (e.g. n dimensional matrix with 4 planes [xyzw]) and transform all of them by a 4x4 transformation matrix.

Is there anything like this?

A Java API for mxf would be even better :) I guess I'm after something like eigen
http://eigen.tuxfamily.org/dox/group__TutorialGeometry.html

Jesse's icon

See: jit.quat, jit.euler2quat, jit.quat2euler, jit.quat2axis, jit.axis2quat

Memo Akten's icon

Hi, yes I know those, but they only do rotation,and not as a matrix (i.e. no basis), also no position, scale or other non-orthogonal transformations. i.e. they're not vector math or basic linear algebra. Just rotations.

EDIT: I've also looked at jim.anim.node, but that seems to be for binding opengl objects and drawing them transformed. Whereas I want to just transform data, lists of coordinates. I.e just a simple matrix multiplication! and be able to construct and deconstruct transformation matrices

vichug's icon

have you tried diving in jit.gen ? That's normally where that sort of stuff is done nowadays

Memo Akten's icon

Yes I have tried jit.gen, it seems to be a type of shader for matrices etc. I'm not sure how it's relevant though, I'd still need to write all the matrix multiplication, matrix inverse etc stuff from scratch as far as I can tell? (unless i've missed some inbuilt functions for basic linear algebra)

Rob Ramirez's icon

the closest thing to what you're asking is the Jitter3DUtils.js extension (search the browser to find this file).

Max Patch
Copy patch and select New From Clipboard in Max.

however, jit.anim.node was designed specifically for these kinds of operations, and functions perfectly without binding to a gl object. here's an example of transforming a list of 3d points by a rotation, and returning the 4x4 transformation matrix:

Jesse's icon

You could also look at the jit.la.* family of objects.

Memo Akten's icon

Rob, that's an interesting use of jit.anim.node, very useful thanks.

Jesse, I missed the jit.la.* commands completely, that's completely it thanks! (actually that's a small subset of what I"m after, but combined with jit.anim.node I can probably easily do everything that I want.)

thanks!

loadmess's icon

Hi from the future!
@Memo Akten, do you think it's possible with a combination jit.la.* objects and jit.anim.node to compute the orthogonal and orthonormal of a given matrix?
Thank you

Memo Akten's icon

Wow this is a blast from the past! To be honest I can't remember anything about jit.

But i can say from what I remember to compute an orthogonal matrix is quite straight forward.
Each row (or column) of your matrix is actually the X,Y,Z axis of a transformation (a basis). And you want to make sure these axes are perpendicular to each other, and normalized.

Pick the 'most important' vector (axis) that you want to retain (typically the 'forward' facing vector, whatever your convention is. E.g. Y or Z).
Cross (product) that with your side vector whatever your convention is (typically X) to get a new 'up' vector perpendicular to your 'forward' vector.

Cross the forward vector with your new up vector to get a new side vector.
Normalize each of these vectors and stack them to get your matrix.

This is from memory so no garantees.

(Also remember A x B = -B x A, so you need to do the cross products in the correct order to make sure you get a right handed or left handed matrix, whichever one you need).

I hope that helps.