# Thread: Obtaining the normal of a plane from the yaw and elevation angles

1. ## Obtaining the normal of a plane from the yaw and elevation angles

Hi,
I wasn't sure if this should be in geometry or trig, so apologies if I picked the wrong one.

My supervisor hinted that the normal of a plane, as viewed from a camera (using the pinhole model) could be obtained from the yaw rotation ($\displaystyle \psi$) and angle of elevation ($\displaystyle \theta$) as per:

$\displaystyle \textbf{\underline{n}}' = \left( \begin{array}{ccc} \cos^{-1}( \psi )\\ \cos( \theta ) \\ \sin( \theta ) \end{array} \right) \quad , \quad \textbf{\underline{n}} = \frac{\textbf{\underline{n}}'}{||\textbf{\underlin e{n}}'||}$

I've since realised that the $\displaystyle \cos^{-1}( \psi )$ is wrong for the x component, and believe it to be $\displaystyle cos( 2\,\pi - \psi )$, although I'm not sure and can't prove it as this is only a hunch. Would anyone be able to help me understand and/or correct this?

EDIT:
I've read up on my vector theory and know that the x component should be $\displaystyle \cos( \psi )$, however this gives me a yaw angle of $\displaystyle 85^\circ$ on an example normal I have, which seems quite unlikely. This could be due to the components being normalised to make the normal vector unit, although I don't know to what extent it would have been normalised. To find my normal, I used a decomposition method from a full camera homography.

2. Hmm. Any chance you could give us a picture of the situation? With angles and plane and normal vector labeled, please? Thanks!

3. A relevant figure from my report is attached. I hope it makes sense. If not, I can draw up a more simple example!

EDIT:
Sorry, I just noticed, this doesn't have the angles on. I've attached another which should hopefully illustrate the angles.

4. Ok, thanks for the pictures. I have a few more questions:

1. What is being held fixed, and what is rotating, when you consider the yaw and angle of elevation?
2. Where is the origin?
3. What variables are known, and what variables are unknown?
4. Does the camera have the ability to measure distances (this is sort of going along with 3)?

Thanks!

5. Hi,

1. I'm working with stationary cameras, with the aim of establishing the normal vector of the linear plane it views. I'm given a fixed angle of elevation (90-180 degrees) and yaw angle (-20 to 20 degrees) and from that need to establish the x, y and z components of the normal to the plane (i.e. it's direction relative to the camera). I'm not sure if that answers your question.
2. At the camera.
3. We know theta and psi but do not know any components of n. We do know that n must be unit, but can normalise to enforce this. We also fix the distance of the camera from the plane.
4. Technically no, it's just a single, stationary, handheld video camera. However we do fix d within a feasible range (emprically gathered) of between 2 and 10 (this is obviously dependant on the context of my work).

A bit of further background to try to explain my problem:

I need this for two key methods:
1. Given the yaw and elevation, I want to be able to construct a simulated plane, i.e. gain the normal, so that I can plot points on the plane, for varying values of "d" (the distance of the camera from the plane).
2. Given some unit normal of a plane, I'd like to be able to assess its validity by determining (approximately) the yaw and elevation angles. I realise there will be difficulties due to the normalisation that may have occured to ensforce the unit-assumption, although am assuming a low normalisation variable (i.e. ||n'|| ~ 1.

6. Ok, so let me re-state the problem, and see if you agree with this (problem definition is absolutely crucial! In my job, I often spend as much time defining a problem as solving it.)

You have a fixed camera that is looking at a plane. This plane has been rotated from what we could call an initial position of being normal to the line between the camera and the point on the plane closest to the camera. This line, from the camera to the point on the unrotated plane closest to the camera, we'll call the z-axis. Now, given that the plane has been rotated about the z-axis through a yaw angle $\displaystyle \psi,$ and then about the x-axis through an elevation angle $\displaystyle \theta,$ find the unit normal vector to the plane.

1. It seems to me that it is the plane that's being rotated relative to a fixed camera. Is that correct?

2. In three dimensions, the order of rotations is important, because it is NOT true that I can do a yaw followed by an elevation, and get the same thing as if I did an elevation followed by a yaw. In two dimensions, rotations are commutative (order doesn't matter), but you obviously have three dimensions. So would you agree that the yaw is happening first, and then the angle of elevation, or is it the reverse that is happening?

Believe it or not, I think we are almost at a solution. It will involve rotation matrices in three dimensions, but I should be able to give you a formula for the normal vector, and show you why it is so.

7. Your statement of my problem seems spot on. Couldn't have put it better myself (quite literally!).

Originally Posted by Ackbeet
1. It seems to me that it is the plane that's being rotated relative to a fixed camera. Is that correct?
I think it's the other way round (unless I've misinterpreted). The plane in question could be, for example, a pavement or road, with a stationary camera being e.g. at the top of a pole. I need to establish the angle of the ground-plane, in order to reconstruct the scene in 3D (to scale).
So in terms of which is fixed, I think it makes more sense to define the ground as fixed, although it's essentially the 3D angle of rotation of the ground W.R.T. the camera I need.

Originally Posted by Ackbeet
2. In three dimensions, the order of rotations is important, because it is NOT true that I can do a yaw followed by an elevation, and get the same thing as if I did an elevation followed by a yaw. In two dimensions, rotations are commutative (order doesn't matter), but you obviously have three dimensions. So would you agree that the yaw is happening first, and then the angle of elevation, or is it the reverse that is happening?
Hmmm, that makes sense, although in terms of which is first, I'm honestly not sure. Would you have any idea which?

I've just had an impromptu meeting with my 2nd supervisor, and he suggested the normal vector could be the following, although wasn't sure:

$\displaystyle \textbf{\underline{n}}' = \left( \begin{array}{ccc} \frac{\pi}{2} - \cos( \psi ) \\ \cos( \theta ) \\ \sin( \theta ) \end{array} \right)$

That seems subjectively feasible to me, although justification-wise I'm a bit dubious.

Thanks very much for your help thus far!

8. Hmm. I hear you, but mathematically, I think you're going to run into problems by thinking about the problem that way. The reason has to do with the origin. If the camera is at the origin, and the plane is fixed relative to that origin, then you always know the unit normal vector! It's just

$\displaystyle \hat{n}=\begin{bmatrix}0\\0\\-1\end{bmatrix}.$

I think you have to think about this problem from "inside the camera". Imagine yourself inside the camera. You're presented with a plane that is normal to your (we'll call it uni-directional) line of vision. All of a sudden, the plane rotates one way, and then another, and the plane is no longer normal to your line of vision. Then, relative to your line of vision in the +z direction, say, you want to know what the normal vector is. Let's idealize this situation, and assume that you can't feel (or measure) the camera rotating (which is what is physically happening, as you've said). I do think that, since the normal vector to the plane is "glued" to the plane, we can think about rotating the plane's normal vector while holding the camera fixed. This is a mathematical construct, I grant you, but I think it's the best way to solve the problem.

In terms of which rotation comes first, I have had to take a test vector, and rotate it in my mind through the two rotations in order to find out which comes first. My hunch is that the elevation has to happen first, because if the yaw happened first, it would leave the normal vector unchanged (vectors don't change if you rotate them about their axis), and hence the yaw angle would have no effect on your final answer (whereas clearly, it does have an effect!).

Here is my analysis, then. The camera is fixed, and is pointing in the +z direction. The normal vector to the unrotated plane is then equal to

$\displaystyle \hat{n}_{0}=\begin{bmatrix}0\\0\\-1\end{bmatrix},$

because it is pointing back to the camera. We apply an angle of elevation rotation, which I'll abbreviate AoE for subscripting purposes. Now, this is tricky, because of the signs. Think carefully here: let's say we're physically rotating the camera through a positive x-rotation. According to the wiki, the matrix

$\displaystyle R_{x}(\theta)=\begin{bmatrix} 1 &0 &0\\ 0 &\cos(\theta) &-\sin(\theta)\\ 0 &\sin(\theta) &\cos(\theta) \end{bmatrix}$

rotates the positive x axis towards the positive y axis. However, since we're looking at everything from the point of view of the normal vector rotating, we have to change the sign of the angle (that is, change the direction from clockwise to counter-clockwise). Hence, utilizing the evenness of the cosine function, and the oddness of the sine function (or you could just as easily think of the inverse of the matrix, which, since rotations are unitary, is just the transpose of the original matrix), our rotation is the following:

$\displaystyle R_{\text{AoE}}(\theta)=\begin{bmatrix} 1 &0 &0\\ 0 &\cos(\theta) &\sin(\theta)\\ 0 &-\sin(\theta) &\cos(\theta) \end{bmatrix}.$

Applied to our normal vector, we get

$\displaystyle R_{\text{AoE}}(\theta)\hat{n}_{0}=\begin{bmatrix} 1 &0 &0\\ 0 &\cos(\theta) &\sin(\theta)\\ 0 &-\sin(\theta) &\cos(\theta) \end{bmatrix}\begin{bmatrix}0\\0\\-1\end{bmatrix}=\begin{bmatrix} 0\\ -\sin(\theta)\\ -\cos(\theta) \end{bmatrix}.$

Next, we apply the yaw rotation. Again, the angle must be reversed from the usual z axis rotation,

$\displaystyle R_{z}(\psi)=\begin{bmatrix} \cos(\psi) &-\sin(\psi) &0\\ \sin(\psi) &\cos(\psi) &0\\ 0 &0 &1 \end{bmatrix},$

to obtain

$\displaystyle R_{\text{yaw}}(\psi)=\begin{bmatrix} \cos(\psi) &\sin(\psi) &0\\ -\sin(\psi) &\cos(\psi) &0\\ 0 &0 &1 \end{bmatrix}.$

Applying this to our already-angle-of-elevation-rotated normal vector yields

$\displaystyle R_{\text{yaw}}R_{\text{AoE}}(\theta)\hat{n}_{0}= \begin{bmatrix} \cos(\psi) &\sin(\psi) &0\\ -\sin(\psi) &\cos(\psi) &0\\ 0 &0 &1 \end{bmatrix}\begin{bmatrix} 0\\ -\sin(\theta)\\ -\cos(\theta) \end{bmatrix} = \begin{bmatrix} -\sin(\psi)\sin(\theta)\\ -\cos(\psi)\sin(\theta)\\ -\cos(\theta) \end{bmatrix} =-\begin{bmatrix} \sin(\psi)\sin(\theta)\\ \cos(\psi)\sin(\theta)\\ \cos(\theta) \end{bmatrix}.$

This, then, is my candidate answer for the normal vector after the rotations you've indicated. It's definitely plausible, because it looks a lot like the transformation into spherical coordinates, which transformation involves an angle of elevation rotation about the x axis, followed by the yaw rotation about the z axis. You can also verify, in a straight-forward manner, that this rotated vector is a unit vector with the usual Euclidean norm.

Do run this candidate through some tests, and see if it gives you plausible answers. I may not have thought through the problem carefully enough, and I may have gotten directions mixed up.

9. I cannot thank you enough for your help. That all makes perfect sense, and having run some tests, seems to give feasible answers.

Thanks again for helping me work through this, and your clear and detailed explanations!
Ian

10. Great! You're very welcome. It was a very fun problem.