How can I create 2D projections from a 3D object?

조회 수: 22 (최근 30일)
Eric
Eric 2016년 5월 10일
댓글: DGM 2025년 7월 29일
I know I can use "radon" for creating 1D projections from 2D, but how can I get 2D projections from 3D objects (such as from a 3D file like an STL file).

답변 (2개)

Mike Garrity
Mike Garrity 2016년 5월 10일
One approach is the technique I showed in answers to this question, and this question.
The basic idea is that you take keep the faces of your geometry, but project the vertices onto the plane. That does mean that you've got multiple conincident polys, so it's not good for things like area computation. But if you just want the visual result, it works well and it's simple.
  댓글 수: 2
Thomas Cornew
Thomas Cornew 2018년 5월 10일
Hello Mike,
How would I approach this problem if I was trying to solve for the area of the 2d projection?
Naveen Pathak
Naveen Pathak 2021년 6월 7일
Hi Mike,
I have a simliar problem. Please, could you help me to plot the following:
Thank you.

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


Y.S.
Y.S. 2023년 3월 29일
2 methods I found that I want to place here for future reference:
[1] fast, but only works for convex shapes. Assuming you have a struct (fvIn) with vertices & faces
fvIn.vertices(:,3)=0; % squash all Z coords
verts = fvIn.vertices;
faces = fvIn.faces;
a = verts(faces(:, 2), :) - verts(faces(:, 1), :); % compute area of all triangles
b = verts(faces(:, 3), :) - verts(faces(:, 1), :);
c = cross(a, b, 2);
area2 = 1/2 * sum(sqrt(sum(c.^2, 2))); % Calculate total area, but this gives double the area because the shape is squashed
Ap = area2/2; %
[2] slow, but works for all shapes
Loop over all triangles, project them on the Z=0 plane, create a polyshape and combine(union) it with the other projected triangles
P = fvIn.vertices(fvIn.faces(1,:),1:2);
psSurfTot = polyshape(P);
for N = 2:size(fvIn.faces,1)
P = fvIn.vertices(fvIn.faces(N,:),1:2);
psSurfTMP = polyshape(P);
psSurfTot = union(psSurfTot,psSurfTMP);
end
% calculate projected area
Ap = area(psSurfTot);
I am still looking for a fast method that works for all shapes, but havent found any
  댓글 수: 3
Seung Jae Lee
Seung Jae Lee 2023년 4월 5일
Hi, Naveen. How could you solve this problem? Can you please share your findings?
DGM
DGM 2025년 7월 29일
We can save some time in the polyshape example if we know our model is a closed surface.
unzip utahteapot.stl.zip % for the forum
% the model is a closed surface, but is self-occluding
T = stlread('utahteapot.stl');
[F V] = t2fv(T); % for conciseness
% just get the upper faces
N = faceNormal(T);
topfaces = N(:,3) > 0;
Ft = F(topfaces,:);
% combine as a polyshape vector
nfaces = size(Ft,1);
PS = repmat(polyshape(),[nfaces 1]); % preallocate
for k = 1:nfaces
P = V(Ft(k,:),1:2);
PS(k) = polyshape(P);
end
PS = union(PS); % then take the union at once
% results
plot(PS)
area(PS) % same answer
ans = 103.5117
At least for me, on this model, these two changes reduce the execution time by about 60%.
Obviously, if our model isn't a closed surface, then we can't make such a simple elimination of faces by orientation. We could still save some time by doing the union() outside the loop though.
One might be tempted to find the free boundaries of Ft and then construct a much shorter polyshape vector to save more time. The problem with that is that such a surface can still be self-occluding, so the projected boundary curve will be self-intersecting. It just creates new problems to solve.

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

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by