# How to get Y rotation from point normal?

## Recommended Posts

Hi!

I have a simple setup where a set of points are facing the camera. I would like to get the points rotation around the y axis so that I can give them different attribute values based on that. How can I calculate this value?

angle.hipnc

##### Share on other sites

i tinkered a bit here...you can use attribrandomize to adjust the variance...but it's not answering your question directly tho...

(i animated the camera)

angle_mod.hipnc

##### Share on other sites

Thanks Noobini, randomness is great. But yes, I would like to know how many degrees the point needed to rotate around the y axis to aim towards the camera, compared to its initial value.

##### Share on other sites
44 minutes ago, otto said:

Thanks Noobini, randomness is great. But yes, I would like to know how many degrees the point needed to rotate around the y axis to aim towards the camera, compared to its initial value.

Use a Point Wrangle, and for each point calculate the vector that goes from the camera to each point, normalize it, calculate the dot product of this vector and the normalized « aim » vector of the camera (I don’t know what kind of setup you have, if the camera will move etc... but it should be easy to compute or to create), and use the arccosine trigo function to get the angle (should be Y if the aim vector and the « target » vector toward each points are in the horizontal plane)

Hope this helps

Edited by StepbyStepVFX
• 1

##### Share on other sites

Thanks for the pointers, @StepbyStepVFX. My knowledge of VEX isn't great, but I'll give it a go.

##### Share on other sites

I will try to open your file and post a result when i can access my computer (when will there be a houdini version for iPad ??? :-)

• 1

##### Share on other sites

Hi, I've attached a file where I added a point attribute called "angle", the computation is based on a forward direction. Is this what you were after?

H16.5.438 Apprentice

angle_v2.hipnc

• 1

##### Share on other sites

Thank you so much @galagast! This was exactly what I wanted. I did a small change, I connected the input normal of the point, before it was aimed towards the camera, and connected that to the dot product node and it works like a charm.

Thanks for the time, to both of you.

Yes, would it be great with iPad support, @StepbyStepVFX, we could bring Houdini with us everywhere

Edited by otto

##### Share on other sites

Hello again

I have another newbie question. Is it possible to get negative values for the angles as well? The dot product and arccosine calculation seems to only give positive values.

In my setup I have a bunch of points with normals all pointing in one direction. I run them through the calculation described above by @StepbyStepVFX  and @galagast aiming the normals towards the camera and calculation the angle. If you look at the image I first posted and the center value is zero (as the original normal is pointing directly towards the camera), I am now getting positive values that increase towards the edges of the image on both side. I was sort of expecting one of the sides to be negative, as the angles are opposite compared to the original normal. Is it possible to get negative values as well?

##### Share on other sites
7 hours ago, otto said:

Hello again

I have another newbie question. Is it possible to get negative values for the angles as well? The dot product and arccosine calculation seems to only give positive values.

In my setup I have a bunch of points with normals all pointing in one direction. I run them through the calculation described above by @StepbyStepVFX  and @galagast aiming the normals towards the camera and calculation the angle. If you look at the image I first posted and the center value is zero (as the original normal is pointing directly towards the camera), I am now getting positive values that increase towards the edges of the image on both side. I was sort of expecting one of the sides to be negative, as the angles are opposite compared to the original normal. Is it possible to get negative values as well?

Indeed, arcosine cannot know if your angle is x or 2*Pi - x, as both of them have same cosine. To work fully, you will need to build an up-vector, make a cross product between your up-vector and your « aim vector » (direction where camera is pointing), and make a new dot product between this new vector and the vector « camera-point » (as before). If they are in the same direction, dot product should be positive, and hence the arcosine gives you the right angle, if this is negative, then you have to take 2*Pi - arcosine.

Just review if I am not mistaken myself in trigonometry before implementing that, I doing it quickly wihtout verification :-)

• 1

##### Share on other sites

You are a star, @StepbyStepVFX! That worked, thanks!

## Create an account

Register a new account