Create a 3D patch faces matrix from vertices matrix

조회 수: 7 (최근 30일)
Guy Trakht
Guy Trakht 2020년 6월 17일
편집: Guy Trakht 2020년 6월 17일
Hello,
im trying to convert 2D patches to 3D patches (extrude the 2D poligon) . for that purpose i already have a vertices matrix but im trying to build the faces matrix as said in the MATLAB documentation, but i cant follow the logic for 'n' lines polygon, (for example a star shape) . im looking for a function that gets the left matrix and returnes the right matrix. many thanks to the helpers
  댓글 수: 4
KSSV
KSSV 2020년 6월 17일
Where are the connections?
Guy Trakht
Guy Trakht 2020년 6월 17일
sorry for the missing data.. the 6'th point is above the 1'st , 7th' is above 2nd' and so on.. two identicle polygons - one on top the other. i hope this is more clear now

댓글을 달려면 로그인하십시오.

채택된 답변

Guy Trakht
Guy Trakht 2020년 6월 17일
편집: Guy Trakht 2020년 6월 17일
function [faces_matrix] = vertices2faces (vertices_matrix)
%this function recives vertices matrix for an 'n' lines polygon and
%returnes the faces matrix - only works with extruded straight up polygons
wall_faces = zeros(length(vertices_matrix)/2,4);
for i=1:(length(vertices_matrix)/2-1)
wall_faces(i,:) = [i, i+1, i+1+length(vertices_matrix)/2, i+length(vertices_matrix)/2];
end
wall_faces (i+1,:) = [length(vertices_matrix)/2, 1, length(vertices_matrix)/2+1, length(vertices_matrix)];
top_and_bottom_faces = [1:length(vertices_matrix)/2;length(vertices_matrix)/2+1:length(vertices_matrix)];
%in a case that the tom and bottom faces are with less vertices then the walls
if length(vertices_matrix)/2<4
faces_matrix =[wall_faces; top_and_bottom_faces, top_and_bottom_faces(:,1)];
else
for j=5:length(vertices_matrix)/2
wall_faces(:,j) = wall_faces(:,1);
end
faces_matrix = [wall_faces; top_and_bottom_faces];
end
end

추가 답변 (1개)

KSSV
KSSV 2020년 6월 17일
Are you looking for something like this?
data = [-0.293 -0.404 0;
-0.475 0.154 0;
0 0.5 0;
0.475 0.154 0;
0.293 -0.404 0;
-0.293 -0.404 1;
-0.475 0.154 1;
0 0.5 1;
0.475 0.154 1;
0.293 -0.404 1]
%% the first 5 rows are the bottom vertices , the last 5 are the upper
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
yi = linspace(min(y),max(y),10) ;
zi = linspace(min(z),max(z),10) ;
[Y,Z] = meshgrid(yi,zi);
X = griddata(y,z,x,Y,Z) ;
surf(X,Y,Z)
  댓글 수: 1
Guy Trakht
Guy Trakht 2020년 6월 17일
no, just want to create the face matrix from the given vertices. without meshing any data.
i appreciate your help

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by