Loading

Some Matrix Maths for OpenScad

by WilliamAAdams, published

Some Matrix Maths for OpenScad by WilliamAAdams Jun 19, 2011

Description

Sometimes I find myself getting lost in the declarative transform world of OpenScad...

translate()
rotate()
scale()
rotate()
.
.
.

Then I smacked my head and discovered 'multmatrix()'

I know you, as I, have often wondered, 'what is the multmatrix?'

This thing is the answer. Basically a bunch more matrix routines to make life in OpenScad easier. Really I'm releasing this particular bit of work because I want to write an expose on declarative vs imperative programming and how to mix the two for 3D design goodness.

What you'll find in this package are functions such as:
vec4_mult_mat4(v,m)
mat4_mult_mat4(m1,m2)
mat4_transpose(m)
transform_scale(xyz)
etc.

The devotees of OpenScad might find the gem known as 'ccerp' and begin to wonder what kind of crack I've been smokin on this father's day. But, that's for another post.

The bottom line with this is, you can do your own fancy matrix transforms, and apply them wherever and whenever you like using the 'multmatrix()' module.

Most people will scratch their heads in wonderment. Some might start bouncing down the halls with glee. The rest will just click on the next Colbert mash up.

Recent Comments

view all

In the very simplest of cases, a transpose can take you from row major to column major form. In my matrix functions, I'm assuming things are layed out in rows. The 'multimatrix()' module assumes a column order, at least with respect to the translation. A simple 'transpose' will take you from my row major order to the column major order OpenScad expects.

The real value of these matrix functions are in being able to deal with curves as simple matrices, but that's not what I'm highlighting as yet, unless you take a look at ccerp().

ok, i can see the utility of using 4d matrix algebra to do scaling, rotating and translating, but what would you use a transposition for?

follow the white multirabbit...

Liked By

view all

License

Public Domain
Some Matrix Maths for OpenScad by WilliamAAdams is licensed under the Public Domain license.

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag

Instructions

1) Download the maths.scad
2) Use it to explore and learn about using matrices for graphics
3) Rejoice!

If you have been playing with things like the hermite surfaces library, this one is not compatible with that one. Basically, the hermite looks like this:

[[P0, M0], [P1, M1]]

This thing changes the order to be:

[P0, P1, M0, M1]

So, be warned.

Comments

You must be logged in to post a comment.

MTO on Jun 19, 2011 said:

ok, i can see the utility of using 4d matrix algebra to do scaling, rotating and translating, but what would you use a transposition for?

WilliamAAdams on Jun 20, 2011 said:

In the very simplest of cases, a transpose can take you from row major to column major form. In my matrix functions, I'm assuming things are layed out in rows. The 'multimatrix()' module assumes a column order, at least with respect to the translation. A simple 'transpose' will take you from my row major order to the column major order OpenScad expects.

The real value of these matrix functions are in being able to deal with curves as simple matrices, but that's not what I'm highlighting as yet, unless you take a look at ccerp().

aubenc on Jun 19, 2011 said:

follow the white multirabbit...

Top