Jump to content

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;

rotate_around_y.thumb.PNG.c10ec1a7d214edcd67767ecb317377d4.PNG

 

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;

rotate_affects_scale.thumb.PNG.928d9c14188853c465bd7bbf913737a6.PNG

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;

rotate_around_normalize.thumb.PNG.5e6c58e78518f14d4d385dda1b604cf5.PNG

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.

original_box.thumb.PNG.70f02eae0bd9da30a296864ca847f878.PNGcopy_stamp_origin.thumb.PNG.cf63b4d7668bc3a41c3f4064a71d4ca7.PNG

 

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

shit_happens.thumb.PNG.6078639a8d17d4fd4d41396f6bba522f.PNG

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);

 

orient.thumb.PNG.04936cb2a8040154e8d6dc1e31a90f12.PNG

 

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

Link to comment
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;

 

matrices_me.hipnc

 

-matt

 

  • Like 1
Link to comment
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).

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...