# my plane is not vertical, How to update 3D coordinate of point cloud to lie on a 3D vertical plane

I have a bunch of points lying on a vertical plane. In reality this plane should be exactly vertical. But, when I visualize the point cloud, there is a slight inclination (nearly 2 degrees) from the verticality. At the moment, I can calculate this inclination only. Concerning other errors, I assume there are no shifts or something like that.

So, I want to update coordinates of my point data so that they lie on the vertical plane. I think, I should do some kind of transformation. It may be only via rotation along X-axis. Not sure what it would be.

I guess, you understood my question. Honestly, I am poor at mathematics. So, please let me know how to update my point coordinates to lie on the exact vertical plane.

If I say exactly what I have done so far; I have point cloud data representing a vertical object + its surroundings things. (The data is collected by a moving scanner and may have axes deviations from the correct world axes). The problem is, I cannot say exactly that there is an error on my data or not. Therefore, I checked this with a vertical planar object (which is the dominated object in my data as well). In reality that plane is truly vertical. But, when I fit a plane by removing outliers, then that plane is not truly vertical and has nearly 2 degree inclination. Therefore, I am suspecting that my data has some error. So I want to update all my point clouds (including points on the plane and points which represent other objects) in a way to lay that particular planar points exactly on the vertical plane. Then, I guess, all the points will be updated into their correct positions as in the reality. That is all (x,y,z) coordinates should be updated.

As an example please refer the below figure. This shows a profile view of my 3d point clouds. left-represents original point cloud (as you can see, points themselves are not vertical) and back line tells the vertical plane which I fitted and red is the zenith line. as you can see, there is an inclination of the vertical plane. So, I want to update whole my data in the right figure. then, after updating if i fit a plane again (removing outliers), then it is exactly parallel to the zenith line. please help me.

• 2D case

If we denote the plane in your picture as the $(x,y)$ plane, let the line $l$ in the left most picture be given by the expression

$$y=mx.$$

For simplicity I have chosen the $(x,y)$ coordinates, s.t. the line $l$ passes through the point $(0,0)$.

You need a coordinate transformation (in this case a rotation) such that, w.r.t. the new coordinates $(X,Y)$ the line $l$ is vertical, i.e. it is described by the equation

$$X=0,$$

which denotes the $Y$-axis (again, in the new coordinates).

By definition of lines in analytic geoemtry, the quantity $m$ is equal to

$$m=\tan(\alpha)=\frac{\sin(\alpha)}{\cos(\alpha)},$$

where $\alpha$ denotes the angle between the positive $x$-axis and the line $l$.

The $(X,Y)$ coordinates are obtained by choosing a counterclockwise rotation of an angle $\beta$, with

$$\beta=\frac{\pi}{2}-\alpha.$$

You can check that this rotation sends the line $l$ to the vertical axis, as requested. The explicit formula for such rotation is

$$X=x\cos(\beta)+y\sin(\beta)$$ $$Y=-x\sin(\beta)+y\cos(\beta).$$

All you need is to compute the line $l$ through linear regression methods (if you arrive at a line $y'=mx'+q$ with non zero $q$, then change coordinates $x=x'$, $y=y'-q$ so you can use the line $l$: $y=mx$), deduce its coefficient $m$, then compute $\alpha=\arctan(m)$ and arrive at $\beta$.

• 3D case (simplified)

Let us consider the 3D case shown in the following (quite bad) picture

Let us suppose that the regression line $l$ lies in the $(z,y)$-plane and passes through $(0,0)$. $\alpha$ is the angles that defines the line $l$, whose points $(x,y,z)$ satisfy

$$(x,y,z)=(0,y,my),~~m=\tan(\alpha).$$

If we want to find a new coordinate system $(X,Y,Z)$ s.t. the line $l$ is the vertical axis $X=Y=0$ in the new coordinates, we need to consider a rotation around the $x$-axis, which is left fixed. The angle of the counterclockwise rotation is determined as in the 2D case, and it is equal to

$$\gamma=\frac{\pi}{2}-\alpha.$$

The new coordinate system $(X,Y,Z)$ is given by

$$X=x,$$ $$Y=y\cos(\gamma)-z\sin(\gamma),$$ $$Z=y\sin(\gamma)+z\cos(\gamma).$$

• 3D Case (more general)

If the line does not lie in the $(y,z)$ plane we are in the more general situation given in the picture below.

We need to rotate counterclockwise around the $z$-axis w.r.t. and angle equal to

$$\delta=\frac{\pi}{2}-\beta$$

to obtain a line lying in the $(Z',Y')$-plane. This rotation is obtained using the coordinate transformation

$$X'=x\cos(\delta)+y\sin(\delta)$$ $$Y'=-x\sin(\delta)+y\cos(\delta).$$ $$Z'=z$$

In the new coordinate system $(X',Y',Z')$ we are left with a rotation of an angle equal to $\frac{\pi}{2}-\alpha$ around the $X'$ axis to move the line to the vertical axis. Repeating the lines of the simplified 3D case we arrive at the needed transformation.

• thank you very much for the response and the way. But I am working on 3D point clouds. So, can I follow this way. I have drawn the figure, when we look at a side on the data. sorry for the misguiding you. If the solution for 3d case is differ with what you explained, could you please update this answer please. I was struggling couple of days. thanks again. – gnp Jul 7 '13 at 15:35
• @gnp you are welcome. If the data lie in a plane in the 3D space, then the above formulae are easy to generalize. I will edit my answer, then. – Avitus Jul 7 '13 at 15:39
• many many thanks. it is a grate help as my point data represent 3d space. I have vertical planar, spherical and all type of features on the site. – gnp Jul 7 '13 at 15:41