how to draw a plane from X Y Z points
21 views (last 30 days)
I have a X, Y , Z vectors with 15k points that represents the response of a system through the time. There is posibility to draw a plane of 13x17 using this data only?
I know how to create a plane asigning the values of Z at the vertexes of the X Y plane, but my idea is now to use this 3 vectors to create somehow a plane of the same dimension as the first one.
% fp function for van der pol system plant (P plant)
[X,Y]=meshgrid(d1,d2); % creates a 13x 17 plane
%values of both functions x2prima at vertexes
PLUT= fp(X, Y)
Here is a code fragment that fits a plane to the 3D data in the file, and plots the 3D data from the file as well as the points on the best-fit plane.
%skip row 1 since fintcp(1)=NaN
fintcp=fintcp(2:end); x1cp=x1cp(2:end); x2cp=x2cp(2:end);
mdl=fitlm([x1cp;x2cp]',fintcp'); %fit linear model
d1=(-4:0.5:4); %mesh x-coordiates
d2=(-3:0.5:3); %mesh y-coordinates
[X,Y]=meshgrid(d1,d2); %create X,Y meshes, 13x17
%Next lines use the linear model to predict z-values at the mesh points
Xv=reshape(X,,1); Yv=reshape(Y,,1); %reshape meshes into vectors
Xall=[ones(size(Xv)),Xv,Yv]; %221x3 matrix for linear prediction
zpred=Xall*mdl.Coefficients.Estimate; %vector: 221 predicted values
zpred=reshape(zpred,size(X)); %reshape vector to mesh
xlabel('X'); ylabel('Y'); zlabel('Z'); hold on; grid on
After you run this, you can rotate the 3D plot by clicking on the 3D rotate icon at the top, then click and drag in the plot.
Try it. Good luck.
More Answers (1)
Edited: William Rose on 3 Oct 2022
[edit: corrected a + that should have been -, on right side of equation z=... below]
It seems that you are using the word "plane" for a surface that is not a plane. Therefore I am not sure if I understand your question. The first part of your code created a non-planar surface with 13x17 points. The second part of your code generates a 3D curve, using data from file points.mat. It appears that this curve also does not lie in a plane.
If you want to fit a smooth non-planar surface to the data in points.mat, you can try fitting a quadratic surface such as
or the more general
(The factors of 1/2 in the first equation are to make it consistent with the second equation. The second equation is a general quadratic surface. By defining it this way, you can compute important quantities as explained here.)
If you want the best fit plane to either data set, you can use multiple linear regression or singular value decomposition. The former will minimize the z-axis errors. The latter will minimize the sum of the perpendicular distances between the measured points and the plane.