# Rotation perpendicular to selected face

## Recommended Posts

Guys, how can I rotate mesh perpendicular to selected face of another mesh? I know that I must use normal of picking element, but what's next? Ty

##### Share on other sites

perpendicular is not enough for information ...

If you want the mesh2 to be perpendicular to some mesh1 face, you may tell us also how you want this mesh2 oriented ? looking at the screen ? looking at the sky ? etc

Actually you may precise 2 other more axis (the picked normal is the first one).

In your case, I would set 3 orthogonal axis (normal, Y, cross(normal, Y) if it's what you need) then I would use rotationFromAxis() to get the rotation to give to the mesh2.

##### Share on other sites

jerome, thank you for response. I made playgorund http://www.babylonjs-playground.com/#2C8LVE#1 but have problem with correct rotation

it is best that mesh face to screen but it's not so important.

##### Share on other sites

Do you mean that you prefer the monkey looks towards the same direction of the mesh normal ?

##### Share on other sites

no, must be perpendecular to face. I released it. but not sure it's correct algoritm (i'm like that monkey - brute the solution )

##### Share on other sites

I don't get what you are try to achieve ...

Imagine you just display Suzanne in its local (X,Y,Z) axis, ok ?

Now, just figure out how you want these (X, Y, Z) according to each mesh facet. "Perpendicular" is not enough information to set (X, Y, Z)

You could, for instance want :

Z => facet normal

Y => World Y ? or World Y projection on the facet normal ? or whatever ? only you know

X => cross(Y, Z)

Or anything else ... that's just an example

##### Share on other sites

I think the question is - why isn't the lovely Suzanne not straight on the box - see image

The answer would be - the mesh is rotated. The normal is not rotated, it is the original normal. So you will just need to take the rotation of the mesh into account, and - tada

##### Share on other sites

not sure,

in his last example, C75 computed a cross vector with from a mysterious axis (1, 1, 1) at the line 112 ...

##### Share on other sites

16 hours ago, jerome said:

not sure,

in his last example, C75 computed a cross vector with from a mysterious axis (1, 1, 1) at the line 112 ...

Yes, that was random vector (bruted finding needful rotation), I tried to use lying mesh, and rotation formula became easier. Check it http://www.babylonjs-playground.com/#2C8LVE#6

and my final "clean" formula with standing  Suzanne  is here http://www.babylonjs-playground.com/#2C8LVE#7

But i'm still can't find solution to merge rotation of mesh and normal (@RaananW said about that). What methods I should use?

##### Share on other sites

Hi,

this is easily solved with quaternions :

Maybe some math wizards can help better with the rotation vector, but I find quaternion multiplication the easiest and the most understandable

## 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.

×