I have a plane $P = ax+by+cz + d = 0$ and many points on that plane.
I want to rotate $P$ so that it becomes parallel to $z = 0$ plane. Which method should I use? I know that the normal vector of my plane is $(a,b,c)$. But I couldn't handle the operations. Can you help me?
@alex.jordan I could not comment since the character limitations. When I display my points, I see that they still have z coordinates. Here are some examples:
Points in:
(0.185237, 0.000000, 3.213694)
(2.811481, 0.000000, 5.276483)
(9.036226, 0.000000, 3.038835)
(0.231554, 0.000000, 8.820473)
Points out:
(-0.000000, 3.213694, 0.185237)
(-0.000000, 5.276483, 2.811481)
(-0.000000, 3.038835, 9.036226)
(-0.000000, 8.820473, 0.231554)
Points in:
(2.936906, 6.026721, 5.531595)
Points out:
(-4.910498, 6.153035, 3.684087)
Points in:
(0.038637, 2.216165, 1.576430)
(4.368976, 3.383844, 5.036302)
Points out:
(1.936124, 1.894746, 0.243656)
(2.626620, 4.911774, 4.987788)
Points in:
(0.870159, 2.345252, 3.526318)
Points out:
(2.346639, 0.044205, 3.630928)
Points in:
(2.296563, 3.377942, 4.388633)
(3.367447, 8.511868, 4.610036)
Points out:
(1.851119, 3.250218, 4.685534)
(3.252196, 8.294517, 5.066384)
I paste my code here:
public static List<Point3d> rotateToXY(List<Point3d> pointList, Equation eq)
{
List<Point3d> points = new ArrayList<>();
double theta = Math.atan((eq.b/eq.a));
double phi = Math.atan(eq.c/ (Math.sqrt(Math.pow(eq.a, 2)+ Math.pow(eq.b,2)) ));
double sinT = Math.sin(-1*theta);
double cosT = Math.cos(-1*theta);
double sinP = Math.sin((Math.PI/2) - phi);
double cosP = Math.cos((Math.PI/2) - phi);
double[][] rotateAboutZaxis =
{
{cosT, (-1)*sinT, 0},
{sinT, cosT, 0},
{0,0,1}
};
double[][] rotateAboutYaxis =
{
{sinP, 0, -1*sinP},
{0, 1, 0},
{sinP, 0, cosP}
};
Matrix rotateY = new Matrix(rotateAboutYaxis);
Matrix rotateZ = new Matrix(rotateAboutZaxis);
Matrix rotateYZ = rotateY.times(rotateZ);
for(Point3d p: pointList)
{
double[][] pointCoordinates = {{p.x}, {p.y}, {p.z}};
Matrix coordinates = new Matrix(pointCoordinates);
coordinates = rotateYZ.times(coordinates);
points.add(new Point3d(coordinates.getRowPackedCopy()));
}
return points;
}
Where am I mistaken?
You need any special orthogonal transformation that takes the unit vector $\frac{1}{\sqrt{a^2+b^2+c^2}}(a,b,c)$ to $(0,0,1)$.
In spherical coordinates, $\frac{1}{\sqrt{a^2+b^2+c^2}}(a,b,c)$ is equal to $\big(\cos(\theta)\cos(\varphi),\sin(\theta)\cos(\varphi),\sin(\varphi)\big)$ for longitude $\theta$ and latitude $\varphi$. To find $\theta$ and $\varphi$ in terms of $a$, $b$, and $c$ depends on which octant the point is in, since inverse trig functions are involved. But if the point is in the "first" octant, then $\theta=\arctan(b/a)$ and $\varphi=\arctan\left(\frac{c}{\sqrt{a^2+b^2}}\right)$.
You can then rotate the point to be in the $xz$-plane using rotation by $-\theta$ about the $z$-axis:$$\begin{bmatrix}\cos(-\theta)&-\sin(-\theta)&0\\\sin(-\theta)&\cos(-\theta)&0\\0&0&1\end{bmatrix}$$ and then rotate the result up to the $z$-axis using rotation by $\frac{\pi}{2}-\varphi$ about the $y$-axis: $$\begin{bmatrix}\cos\left(\frac{\pi}{2}-\varphi\right)&0&-\sin\left(\frac{\pi}{2}-\varphi\right)\\0&1&0\\\sin\left(\frac{\pi}{2}-\varphi\right)&0&\cos\left(\frac{\pi}{2}-\varphi\right)\end{bmatrix}$$
In summary, first find $\theta$ and $\varphi$. Then compute $$\begin{bmatrix}\cos\left(\frac{\pi}{2}-\varphi\right)&0&-\sin\left(\frac{\pi}{2}-\varphi\right)\\0&1&0\\\sin\left(\frac{\pi}{2}-\varphi\right)&0&\cos\left(\frac{\pi}{2}-\varphi\right)\end{bmatrix}\begin{bmatrix}\cos(-\theta)&-\sin(-\theta)&0\\\sin(-\theta)&\cos(-\theta)&0\\0&0&1\end{bmatrix}\begin{bmatrix}a\\b\\c\end{bmatrix}$$ and you wind up on the $z$-axis. If $(x,y,z)$ were a point somewhere on the original plane, then $$\begin{bmatrix}\cos\left(\frac{\pi}{2}-\varphi\right)&0&-\sin\left(\frac{\pi}{2}-\varphi\right)\\0&1&0\\\sin\left(\frac{\pi}{2}-\varphi\right)&0&\cos\left(\frac{\pi}{2}-\varphi\right)\end{bmatrix}\begin{bmatrix}\cos(-\theta)&-\sin(-\theta)&0\\\sin(-\theta)&\cos(-\theta)&0\\0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\end{bmatrix}$$ will correspondingly move that point to the $xy$-plane.
Following OP's attempt to apply this, edited into the question:
You tried: $$\begin{align} (0.185237, 0.000000, 3.213694)\\ (2.811481, 0.000000, 5.276483)\\ (9.036226, 0.000000, 3.038835) \end{align}$$ which I guess implies that the plane is $0x+y+0z=0$. With $(a,b,c)=(0,1,0)$, we have $\theta=\pi/2$ and $\varphi=0$. So the matrices above are $$\begin{bmatrix}0&0&-1\\0&1&0\\1&0&0\end{bmatrix}\begin{bmatrix}0&1&0\\-1&0&0\\0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\end{bmatrix}$$
$$\begin{bmatrix}0&0&-1\\-1&0&0\\0&1&0\end{bmatrix}\begin{bmatrix}x\\y\\z\end{bmatrix}$$
$$\begin{bmatrix}-z\\-x\\y\end{bmatrix}$$
For your points, this gives $$\begin{align} (-3.213694, -0.185237, 0.000000)\\ (-5.276483, -2.811481, 0.000000)\\ (-3.038835, -9.036226, 0.000000) \end{align}$$