Object rotation from polygon normal


#1

Hello!

i would like to attach an object to a polygon and have the object aligned to the polygon.

i cannot use mograph to do it beacuse of strange prioriti issues.

i am using polygon node in xpresso, and poly node gives me position and normal of the polygon. how do i get the correct rotation for the object?

thanks!!


#2

Hi,
you can create a global matrix from the polygon center, normal and one of the points of the poly. See the attached scene for an example.
Hope this helps
Björn
MatrixFromPoly.c4d (317.9 KB)


#3

OMG this is brilliant! Thank you so much!! It works perfectily!!!

(i just needed to change the priority of the xpresso tag to avoid priority issues!)

I just dont understand the math behind what you just did, do you know any good online resource (video tutorial or website) that explains this math?

thanks again!!


#4

There are two things at the core of this. First is the way Cinema 4D stores Position, Scale and Rotation of an object. It uses a 3x4 Matrix to do this where Vector 0 contains the position and V1-3 contain the orientation in space. These three vectors are usualy at 90° angles to each other and of length 1. To create an own matrix that aligns the object correctly you can use the existing polygon normal (a normal is a vector with the length 1), a second normal calculated by using one of the points of the polygon and the polygon center, and as the third normal you use the cross product to create it from the two you already know. This cross product is the second element important part.
All in all it is just a bit of vector and matrix calculation and you can read up on it in any Highschool math book.
If you want to go further read up on analytical geometry. In general this kind of knowledge is very helpful if you want to script in 3D applications.
Edit: Disclaimer, i learned this stuff at the polytechnical, but i had to relearn it when i started doing 3D.


#5

thank you very much for your help, i really apreciate it. i guess i will have to study then!