Thingiverse
Quaternions for OpenScad by WilliamAAdams
by Thingiverse
Last crawled date: 3 years ago
Having some basic Matrix math operations available in OpenScad has been a wonderful thing. I found my life to be somewhat lacking though because rotations are a royal pain in the...
This thing adds Quaternion support to OpenScad
Besides sounding like a cool name for an 80s rock band, or a futuristic diabolical planetary leader, quaternions are a math construct that make doing rotations a fairly painless task.
basically: myquat = quat(axis, angle);
So, to do a 30 degree rotation around the z-axis for example, would look like this:
rotz = quat([0,0,1], 30);
Now, that's not going to do you much good in OpenScad by itself, so you need to turn it into a matrix that OpenScad can easily consume and apply as a transform, so you do this:
rotzmatrix = quat_to_mat4(rotz);
Once you have this, you can use it with multmatrix()
multmatrix(rotzmatrix);
or
multmatrix(quat_to_mat4(quat([0,0,1],30)));
Ok, so wow, big deal!!
OK. So, combinations can be done like this:
q1 = quat([0,0,1],30);
q2 = quat([0,1,0], 15);
combo = quat_mult(q1, q2);
multmatrix(quat_to_mat4(combo));
This will combine the 30 degree rotation around the z-axis, followed by the 15 degree rotation about the y-axis, or visa versa.
This is nice, because you can apply this transform anywhere you like, without having to go through gyrations such as:
rotate()
{
rotate()
}
If you've used an instance of this math library in the past, I've made a couple of changes. I've added more vecxxx calls, to support vec2, and vec3 more explicitly. The biggest change is to the mat4 (matrix4x4) routines. Basically, I was storing the data in 'row order' previously, which required a transpose of the matrix before using it with the multmatrix() module. So, I changed the ordering to be column major ordering (for those in the know). That aligns better with what OpenScad expects, so life gets easier as you don't need the transpose in the end.
At any rate, another batch of goodness for OpenScad.
NOTE: the 'quat_to_mat4()' function is an interesting piece of work. The equivalent 'C' code utilizes a lot of variables, which are not a part of OpenScad functions (as opposed to modules). This poses quite a challenge. So, how it's broken down into a cascade of functions demonstrates a general methodology for dealing with 'variables' in functions. Just turn each 'variable' into a function.
UPDATE: 22072011
I left a few routines out from the first release of this thing, so I've added them in:
quat_conj(q) - conjugate of the quaternion
quat_distance(q1, q2) - distance between two quaternions
quat_norm(q) - the 'length' if you will.
quat_normalize(q) - normalize the quaternion
There is one more monster function to add: quat_slerp (spherical interpolation). As this one is more complex than the 'to_mat4', I'm having to think about it for a while. Not too bad, and it will come. Perhaps this will warrant a new version.
This thing adds Quaternion support to OpenScad
Besides sounding like a cool name for an 80s rock band, or a futuristic diabolical planetary leader, quaternions are a math construct that make doing rotations a fairly painless task.
basically: myquat = quat(axis, angle);
So, to do a 30 degree rotation around the z-axis for example, would look like this:
rotz = quat([0,0,1], 30);
Now, that's not going to do you much good in OpenScad by itself, so you need to turn it into a matrix that OpenScad can easily consume and apply as a transform, so you do this:
rotzmatrix = quat_to_mat4(rotz);
Once you have this, you can use it with multmatrix()
multmatrix(rotzmatrix);
or
multmatrix(quat_to_mat4(quat([0,0,1],30)));
Ok, so wow, big deal!!
OK. So, combinations can be done like this:
q1 = quat([0,0,1],30);
q2 = quat([0,1,0], 15);
combo = quat_mult(q1, q2);
multmatrix(quat_to_mat4(combo));
This will combine the 30 degree rotation around the z-axis, followed by the 15 degree rotation about the y-axis, or visa versa.
This is nice, because you can apply this transform anywhere you like, without having to go through gyrations such as:
rotate()
{
rotate()
}
If you've used an instance of this math library in the past, I've made a couple of changes. I've added more vecxxx calls, to support vec2, and vec3 more explicitly. The biggest change is to the mat4 (matrix4x4) routines. Basically, I was storing the data in 'row order' previously, which required a transpose of the matrix before using it with the multmatrix() module. So, I changed the ordering to be column major ordering (for those in the know). That aligns better with what OpenScad expects, so life gets easier as you don't need the transpose in the end.
At any rate, another batch of goodness for OpenScad.
NOTE: the 'quat_to_mat4()' function is an interesting piece of work. The equivalent 'C' code utilizes a lot of variables, which are not a part of OpenScad functions (as opposed to modules). This poses quite a challenge. So, how it's broken down into a cascade of functions demonstrates a general methodology for dealing with 'variables' in functions. Just turn each 'variable' into a function.
UPDATE: 22072011
I left a few routines out from the first release of this thing, so I've added them in:
quat_conj(q) - conjugate of the quaternion
quat_distance(q1, q2) - distance between two quaternions
quat_norm(q) - the 'length' if you will.
quat_normalize(q) - normalize the quaternion
There is one more monster function to add: quat_slerp (spherical interpolation). As this one is more complex than the 'to_mat4', I'm having to think about it for a while. Not too bad, and it will come. Perhaps this will warrant a new version.
Similar models
thingiverse
free
Some Matrix Maths for OpenScad by WilliamAAdams
... heads in wonderment. some might start bouncing down the halls with glee. the rest will just click on the next colbert mash up.
thingiverse
free
Matrix Buildings by ramenspork
...sing the built in rotate, translate, etc. functions, although union, difference, intersection were ok). here are their buildings.
thingiverse
free
Bezier Mesh Surface V0.6 by WilliamAAdams
... the normals pointing in the wrong direction for all cases, nor the short leg syndrome on the triangles, but one step closer now.
thingiverse
free
DOTFONT (variable width OpenSCAD font with by TakeItAndRun
...t generated from a vector matrix.
the black lines in the picture are just a workaround for thingiverse`s picture scaling routine.
thingiverse
free
Easy Bez-curve - Extrude and Distribute anything along Curve - ALL OPENSCAD by Torleif
...aternions and and really needs robust cubic splines. work in progress. stay in school kids you will use that math in the future.
thingiverse
free
Complex cube for Quaternions by SeraphImpaler
...rnions math. it is inspired by the caylay graph on the wikipedia page about quaternions.
https://en.wikipedia.org/wiki/quaternion
thingiverse
free
Your name rotated by nevitdilmen
...cad to rotate less than 360 degrees.
as of this upload customizer does not support rotating less than 360 so i didnt activate it.
grabcad
free
Math Functions With Various Rotation Schemes
...rminated towards.
#ty tells you the function was terminated to the y-axis
#tx tells you the function was terminated to the x-axis
thingiverse
free
Customizable Name Tag by doc
...9;ve made them in to variables at the start of the file so you can somewhat easily completely change the look of the whole thing.
3dwarehouse
free
Blocos dinâmicos e cadeiras.
...as: x - -37.970cm onclick - animateslow('x',-38,4) porta pivotante: rotz - 15 onclick - animateslow('rotz',-75,0)
Quaternions
3d_export
$7
Quaternion Pistol 3D Model
...stol gun game low poly pack
quaternion pistol 3d model download .c4d .max .obj .fbx .ma .lwo .3ds .3dm .stl lukiz 105320 3dexport
3d_export
$38
Female - Type 3
... unreal, rename the armature's name to something else before importing this model. your comments and suggestions are welcome.
thingiverse
free
Complex cube for Quaternions by SeraphImpaler
...rnions math. it is inspired by the caylay graph on the wikipedia page about quaternions.
https://en.wikipedia.org/wiki/quaternion
thingiverse
free
Fractal earrings Quaternion Julia by bennnnnn6
...fractal earrings quaternion julia by bennnnnn6
thingiverse
rotation of the julia fractal for earrings
thingiverse
free
Cubic Quaternion Julia Fractal #1 by theswope
...cubic quaternion julia fractal #1 by theswope
thingiverse
this is only a test.
thingiverse
free
Cubic Quaternion Julia Fractal #2 by theswope
...cubic quaternion julia fractal #2 by theswope
thingiverse
let's do this again
thingiverse
free
Modified Quaternion IFS 3D Fractal by neil95
...y neil95
thingiverse
really neat 3d fractal structure. great for people who like math and/or art.
this might be tricky to print.
thingiverse
free
Xbox One Controller Hanging Mount by quaternion
...helf, place the xbox console on top of the long edge, and it will hold up your controllers. no hardware or installation needed :)
thingiverse
free
Easy Bez-curve - Extrude and Distribute anything along Curve - ALL OPENSCAD by Torleif
...torleif thingiverse yeah, i know it still sucks, no quaternions and and really needs robust cubic splines. work in...
Williamaadams
thingiverse
free
Toy Panel by WilliamAAdams
... most basic pieces of the klikko math system. it is a builder system where you can click panels together to form various shapes.
thingiverse
free
Yazzo by WilliamAAdams
...the connectors. the openscad file allows you to parameterize these connectors, and create any sizes you might want to play with.
thingiverse
free
Gandhi Lithophane by WilliamAAdams
...a lithophane of gandhi on a stamp.
any number of lithophane prints can be made by simply changing a file name in the .fab script.
thingiverse
free
Yazzo Servo Linkage by WilliamAAdams
...elative sizing of things. by default the arm is 1/2" thick to match the size of the sleeve bearing that's at the joint.
thingiverse
free
Faceted Drinking Cup by WilliamAAdams
...se for quite some years, but i was getting thirsty, so i designed this simple cup to test out printing with translucent filaments
thingiverse
free
Yazzo UClip Keyed by WilliamAAdams
...tandard key on the edge of it, so that you can attach something, or a number of things to it by sliding the key into their notch.
thingiverse
free
Cobra Chair by WilliamAAdams
... curves, and see how the curve reacts. it would probably be much easier to model with a different type of curve, but here it is.
thingiverse
free
Coaster Blob by WilliamAAdams
...s a convenient blobby cup holder. put some sticky rubber feet pads on the bottom, and it will make a nice addition to your desk.
thingiverse
free
Yazzo Female Clevis by WilliamAAdams
...mm plastic filament probably. good enough for prototyping. printing on its side would probably be best for structural strength.
thingiverse
free
Simple Tetrahedron by WilliamAAdams
....
this thing is a simple vertex constructed from vinyl tubing. there are no actual files, only pictures that show the technique.
Openscad
thingiverse
free
OpenSCAD sphere
...openscad sphere
thingiverse
basic project for openscad.
thingiverse
free
Openscad Football by KySyth
...openscad football by kysyth
thingiverse
openscad not tested
thingiverse
free
Openscad Apple by KySyth
...openscad apple by kysyth
thingiverse
openscad apple = not tested
thingiverse
free
Plugs with openscad by benengel
...plugs with openscad by benengel
thingiverse
plugs with openscad and fontawesome
thingiverse
free
Openscad spirals by mafmuf
...openscad spirals by mafmuf
thingiverse
just fooling around with openscad.
thingiverse
free
Practice on OpenScad by ajensen906
...practice on openscad by ajensen906
thingiverse
a very crude practice on openscad
thingiverse
free
Batteries in OpenSCAD by roman_hegglin
...batteries in openscad by roman_hegglin
thingiverse
common batteries as modules for openscad.
thingiverse
free
OpenScad Propeller by KySyth
...se
trying to make a propeller with openscad = not tested
this is some of the results
added the openscad file but still need work
thingiverse
free
Openscad Cloud by Twanne
...openscad cloud by twanne
thingiverse
openscad cloud.
size can be adjusted
thingiverse
free
Geomag for OpenScad by vicnet
...geomag for openscad by vicnet
thingiverse
openscad file to design geomag things.