How can I make 3d plots of planes by using spreadsheet in matlab

不羁的心 提交于 2020-01-11 13:02:31

问题


pointA=[9.62579 15.7309 3.3291];
pointB=[13.546  25.6869 3.3291];
pointC=[23.502  21.7667 -3.3291];
pointD=[19.5818 11.8107 -3.3291];

points=[pointA' pointB' pointC' pointD'];
fill3(points(1,:),points(2,:),points(3,:),'r')
grid on
alpha(0.3)

This code will show a filled plane(Cant add images yet T.T)

Now here is my problem. On a spreadsheet, I have x,y,z coordinates of thousands of points. The 4 consecutive points form a plane like the one shown. How do I make a code such that for every 4 consecutive points, it makes a filled plane. Basically, if I have 400 points, I want the code to plot 100 planes.


回答1:


Assuming your data are a matrix, m = (400,3)

m = rand(400,3); for i = 1:length(m); m2 = m'; % Transpose end

Create a 3-D matrix in which 'j' represents each set of points:

m3=[];

%Not the most elegant way to cycle through every four points but it works!

z = 0:(length(m2)/4); z1 = (z*4)+1; z1 = z1(:,1:length(z)-1); 
    for j = 1:length(z1);
        m3(:,:,j) = m2(:,z1(j):(z1(j)+3));
    end

'j' now has a total length = 100 - representing the amount planes;

fill3(m3(1,:,1),m3(2,:,1),m3(3,:,1),'r'); 

% Cycle through planes- make a new figure for each plane;

for j = 1:length(z1);
    fill3(m3(1,:,j),m3(2,:,j),m3(3,:,j),'r'); 
end



回答2:


clear all, close all, clc
pointA=rand(99,1);
pointB=rand(99,1);
pointC=rand(99,1);
pointD=rand(99,1);
pointAmat = reshape(pointA,3,1,[]);
pointBmat = reshape(pointB,3,1,[]);
pointCmat = reshape(pointC,3,1,[]);
pointDmat = reshape(pointD,3,1,[]);

points=[pointAmat pointBmat pointCmat pointDmat];

for i = 1:size(points,3)
fill3(points(1,:,i),points(2,:,i),points(3,:,i),'r')
hold all
end
grid on
alpha(0.3)

Hope this helps.



来源:https://stackoverflow.com/questions/32185995/how-can-i-make-3d-plots-of-planes-by-using-spreadsheet-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!