3D Convex hull projection on 2D planes
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have the code to plot a convex hull using my data including 3 points. My question is that how I can have a transparent convex hull with its projection on surfaces x-y, x-z, and y-z?
x=[10 10 40 60 60 60];
y=[0 10 40 30 10 0];
z=[10 13 40 60 57 50];
tri = delaunay(x,y);
trisurf(tri,x,y,z)
채택된 답변
Mike Garrity
2015년 6월 16일
Something like this?
x=[10 10 40 60 60 60];
y=[0 10 40 30 10 0];
z=[10 13 40 60 57 50];
tri = delaunay(x,y);
trisurf(tri,x,y,z)
n = length(x);
dx = 60+zeros(n,1) + 5;
dy = 40+zeros(n,1) + 5;
dz = 10+zeros(n,1) - 5;
px = patch('Faces',tri,'Vertices',[dx y' z']);
py = patch('Faces',tri,'Vertices',[x' dy z']);
pz = patch('Faces',tri,'Vertices',[x' y' dz]);
set([px,py,pz],'FaceAlpha',.5,'EdgeColor','none');

댓글 수: 6
Thanks Mike! I also need the transparent figure to see the corners clearly, and each point coordinate with dashed line connecting the corners (including 6 point) to their 2D projected points, is that possible?
I'm not following the part about the transparent figure, but the lines are easy to add:
for i=1:n
line([x(i) dx(i)],repmat(y(i),[1 2]),repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]),[y(i) dy(i)],repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]),repmat(y(i),[1 2]),[z(i) dz(i)],'LineStyle','--')
end
rela rela
2015년 6월 17일
Thank you. May I ask how you calculated the coefficients in dx, dy, and dz? I want to use this method for some other data.
I just made them up. You want an array of the right size which contains constant values for where you want the shadow to be. For example, if I wanted to push the bottom down to Z=-10, I would want this:
dz = [-10; -10; -10; ...]
The numbers I used were just the defaults when I drew your 3D patch, with an extra 5 added (or subtracted) to push things out a little bit.
I use the "K = convhulln(X);" "trimesh(K,X(:,1),X(:,2),X(:,3))" instead of "tri = delaunay(x,y);" for another set of data, the values are different from previous data and also they are 3 points instead of 6, can I used the same dx, dy, and dz for them also? This is the code:
x=[2 7.5 10.5];
y=[8 18.4 25];
z=[16 28.9 44];
% x=[10 10 40 60 60 60];
% y=[0 10 40 30 10 0];
% z=[10 13 40 60 57 50];
X = [x; y; z]'; %# involves a 3D point on each row
K = convhulln(X);
trimesh(K,X(:,1),X(:,2),X(:,3))
% 2D projection
n=length(x);
dx=60+zeros(n,1)+5;
dy=40+zeros(n,1)+5;
dz=10+zeros(n,1)-5;
px=patch('Faces',K,'Vertices',[dx y' z']);
py=patch('Faces',K,'Vertices',[x' dy z']);
pz=patch('Faces',K,'Vertices',[x' y' dz]);
set([px,py,pz],'FaceAlpha',.5,'EdgeColor','none');
% 2D coordinate (Dashed lines)
for i=1:n
line([x(i) dx(i)],repmat(y(i),[1 2]),repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]),[y(i) dy(i)],repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]),repmat(y(i),[1 2]),[z(i) dz(i)],'LineStyle','--')
end
%But it doesnt work, it says
%"Error using cgprechecks (line 40)
%Not enough unique points specified.
% Error in convhulln (line 41)
% cgprechecks(x, nargin, cg_opt);
% Error in Untitled5 (line 12)
% K = convhulln(X);"
% Does it work for you? Because I have a problem,
% when change the folder of my code it gives me an error
% "Attempt to execute SCRIPT trimesh as a function:
%C:\Users\...(?)\Desktop\trimesh.m
% Error in Untitled (line 11)
% trimesh(tri,x,y,z)"
% I should add also I could run the code with previous data (6 points)
% once and it game me the figure, but again when I open and run it,
% it gives the % last error
% ("Attempt to execute SCRIPT trimesh as a function:
%C:\Users\...(?)\Desktop\trimesh.m
% Error in Untitled (line 11)
% trimesh(tri,x,y,z)" ")
There are a couple of different issues here.
This message:
Error using cgprechecks (line 40)
Not enough unique points specified.
is trying to say that 3 points isn't enough to define a convex hull in 3D. You need at least one more than the dimension of the space you're in.
I'm not sure what caused this message:
Attempt to execute SCRIPT trimesh as a function
but it looks like you have a file named "trimesh.m" on your path. If you do this:
which trimesh
it should point you at the "toolbox/matlab/specgraph" directory. If it points somewhere else, you've probably got to delete or rename this extra copy.
It also looks like you've changed the shape of your x,y,z arrays from Nx1 to 1xN. When I created the constant dx,dy,dz arrays, I assumed the first orientation. You'll probably want to fix that, then you can remove some of the transposes. It probably would have been better if I'd created them like this:
dx = 65 + zeros(size(x));
dy = 45 + zeros(size(y));
dz = 5 + zeros(size(z));
px=patch('Faces',K,'Vertices',[dx; y; z]');
py=patch('Faces',K,'Vertices',[x; dy; z]');
pz=patch('Faces',K,'Vertices',[x; y; dz]');
set([px,py,pz],'FaceAlpha',.5,'EdgeColor','none');
for i=1:n
line([x(i) dx(i)], ...
repmat(y(i),[1 2]), ...
repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]), ...
[y(i) dy(i)], ...
repmat(z(i),[1 2]),'LineStyle','--')
line(repmat(x(i),[1 2]), ...
repmat(y(i),[1 2]), ...
[z(i) dz(i)],'LineStyle','--')
end
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Bounding Regions에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
