3 Replies Latest reply on Oct 4, 2006 3:14 AM by Minds Eye

# How do I get a rotation from a normalized vector

Hi
I need to align a cylinder to the face of a mesh that is picked by the user
via the modelsUnderLoc handler

The function gives me #isectNormal as part of the return list which is a normalized vector

All I want to do is rotate my cylinder to align with the normal of the face.

How do I convert this?

Regards,
Trevor

The Minds Eye

• ###### 1. Re: How do I get a rotation from a normalized vector
Hi Trevor,

I think you could place the cylinder at the point of intersection on the
face, then use the pointAt() command to point the cylinder at a vector set
to the world position of the cylinder + the isectNormal vector.

Although I'm sure someone will suggest a more mathtastic way to do it :)

Richard
www.funpods.com

• ###### 2. Re: How do I get a rotation from a normalized vector

After placing the cylinder at the intersect position, do this to adjust the rotation:

tiltAngle = vector(0,0,1).anglebetween(surfaceNormal)
tiltVector = surfaceNormal.perpendicularto(vector(0,0,1))
myModel.transform.rotation = vector(0,0,0)
myModel.transform.rotate(myModel.transform.position,tiltVector,-tiltAngle)

If the cylinder's origin is at its centre, you'll then need to do a 'translate' command, to move it along its own z axis by half its length, so that it sits on the surface of the mesh instead of halfway embedded into it.

hope this helps!

- ben

• ###### 3. Re: How do I get a rotation from a normalized vector
Perfect! Thank you.

Regards,
Trevor

The Minds Eye