# Understanding matrices, quaternions and all that jazz

## Recommended Posts

Hi everyone,

I would like to better understand matrices and how to use them to do what I want. I've prepared a hip file with screen shots of things I get and don't get. While writing this I'm almost making discoveries so please bare with me if it seems like a long thread First off, applying a matrix3 to rotate my points seems fine as long as my vector is normalized. Else, it affects scale as well. Why is that?

1. rotate around y

matrix3 m = ident();
float angle = ch("angle") ;
vector axis = {0, 1, 0} ;
rotate(m, angle, axis);

@P *= m;

2. rotate around {0,1,1}. Not good.

matrix3 m = ident();
float angle = ch("angle") ;
vector axis = {0, 1, 1} ;
rotate(m, angle, axis);

@P *= m;

3. rotate around normalize({0,1,1})

matrix3 m = ident();
float angle = ch("angle") ;
vector axis = normalize({0, 1, 1}) ;
rotate(m, angle, axis);

@P *= m;

Hence, we need to normalize the rotational axis vector to prevent scaling the geometry.

Secondly, I'm having issues setting the pivot for my rotations. In the examples above this all works well if our pivot is set at the origin. So how do we set the pivot to be at the center if our geometry? Please take a look at rotate_not_at_origin object.

To begin this little science experience, I've copy stamped boxes on a single box and used the normals from the orignal box as the rotation axis vector. So far so good.

This all goes to shit if we move our original box from the origin. How do we solve this?

The only way I've seen, and don't understand, is using @orient as follows before the copy stamp. Also, this no longer copies the geometry based on the normal direction of my points.

matrix3 m = ident() ;
float angle = ch("angle") ;
vector axis = normalize(v@rot_axis);
rotate(m, angle, axis);

@orient = quaternion(m);

So how do we solve this? I really need to wrap my head around this once and for all gahhhhh!!

Thanks everyone!

Maxime

matrices.hipnc

##### Share on other sites

It would definitely be nice to have an input for pivot on the rotate function... The work around I do for this: Store the original pivot, move each box back to origin by negating the orig pivot, perform the rotation, then move the boxes back by adding orig pivot.  Did a few example notes in your file.

matrices_a.hipnc

##### Share on other sites

Thanks Arrev, I'll take a look shortly. I have heard of this work around but there must be another way! Thanks for your input ##### Share on other sites

There's clever ways to rotate in place (which I always forget), but just about everyone I know does the simple thing of move stuff to the origin, rotate, put back to the original position.

To make your setup work, I just added an extra wrangle before the copy to points to store the point position, as centroid:

`v@centroid=@P;`

Then in the rotate wrangle, subtract centroid, rotate, add centroid:

```matrix3 m = ident();
float angle = ch("angle");
vector axis = normalize(v@rot_axis);
rotate(m, angle, axis);

@P-=v@centroid;
@P *= m;
@P+=v@centroid;```

-matt

• 1
##### Share on other sites

Thanks Matt!

Love your website btw. Been looking at it every now and then • 1
##### Share on other sites

A quicktip is to use the Deformation Wrangle when doing stuff like this. It will take care of your normals and stuff, rotating them too. When just using a Point Wrangle and modifying P the normals doesn't follow (or any other vectors, velocity for example).

• 2
• 1

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×