Search code examples
matlabrotationmatlab-figureplane

How to rotate a plane over z-axis and y-axis in Matlab?


Given a point (x0,y0,z0) on 3d plane, first I want to plot a plane x=x0 that passes through the given point (x0,y0,z0), and then rotate that plane alpha degree on y-axis and beta degree on z-axis. The final plane should also pass through the point point (x0,y0,z0).

Here is an example when the given point was (4,5,6), alpha=30 and beta=45, and I manage to rotate 30 degree on y-axis only:

x0=4;
y0=5;
z0=6;
alpha=30;
beta=45;
plot3(x0,y0,z0,'r*')
hold on
[Y1, Z1] = meshgrid(linspace(-10,10), linspace(0,10));
X1 = x0*ones(size(Y1));
surf(X1,Y1,Z1)
hold on
xlabel('X');
ylabel('Y');
zlabel('Z');
X2 = (Z1)*tand(alpha)-z0*ones(size(Z1))*tand(alpha)+X1;
surf(X2,Y1,Z1)

Can you please help me to simultaneously rotate original plane x=x0 over y-axis and z-axis, so that the final plane passes through (x0,y0,z0)?


Solution

  • Your initial point are:

    p1 = [x0,y0,z0]
    

    Your initial plane equation is:

    F = a*x + b*y + c*z + d == 0 % with a=1, b=0, c=0 and d=-x0
    F = x == x0
    

    Based on this equation you can generate two more point p2 and p3.

    Apply two rotation matrix Ry and Rz to your points:

    [p1',p2',p3'] = [p1,p2,p3]*Ry*Rz
    

    Then compute your new plane equation F' = a*x + b*y + c*z + d == 0 that fit [p1',p2',p3'] (with a cross product) and finally adjust the parameter d so that F'(p1) = 0. Let's call that new equation F''. You have your final plane equation and you can plot your surface.

    To generate the plane your can again use meshgrid and isolate the z parameter of you F'' function: z = -(a*x +b*y + d)/c