Wrap part of a shape with a surface
35 views (last 30 days)
Show older comments
Robert Demyanovich
on 15 Nov 2025 at 17:29
Commented: Robert Demyanovich
on 16 Nov 2025 at 0:17
I have the following code:
%Initially written by W. Rose 20251018
%Modified by poster rdemyan
clear
N=80; % number of angular steps in one rotation
w=7.908e-4; R=6e-4; % constants in equation for p(t) [units=length]
B=0.867; % constant in equation for h(t): h(t)=B*p(t) [dimensionless]
dt=2*pi/N; % angle step size [radians]
t=(0:dt:2*pi)'; % angle of rotation (vector, length N+1) [radians]
p=((w/2)*cos(t)+(R^2*(sin(t).^2+0.5*cos(t).^2)-(w^2/2)*sin(t).^2).^0.5)./(sin(t).^2+0.5*cos(t).^2);
% Compute h(t):
h=B*p;
% Compute arrays of 3D points
pt=[p.*cos(t),p.*sin(t),h/2]; % x,y,z coords of points along top of shape
pb=[p.*cos(t),p.*sin(t),-h/2]; % x,y,z coords of points along bottom of shape
figure
for i=1:N+1
view(40,60);
hold on;
axis equal;
% Draw HEIGHT LINES between top and bottom points
f=plot3([pt(i,1),pb(i,1)],...
[pt(i,2),pb(i,2)],...
[pt(i,3),pb(i,3)],LineWidth=4)
f.Color = [0,0.7,0.7,0.7]
drawnow;
end
With N = 80, I get the following shape.

With N = 2000, I get the following shape:

Instead of increasing N I would like to wrap the height lines with a surface. Increasing N does provide a passable figure, but there are lines that have an uneven transparency. Yes, if I increase FaceAlpha to 1, then there is no uneveness, but I want to have some transparancy. I think that a surface wrap might produce a much more uniform figure and also I would like to decrease the FaceAlpha value further from the value of 0.7. Further, for my own edification, I would like to know how to wrap the height lines in a surface to create the desired figure rather than just increasing the value of N. Finally, I do not want to have a top or bottom surface, just wrapped around as shown in Fig. 2. I want to be able to "see" inside as shown.
1 Comment
Rik
on 15 Nov 2025 at 19:04
Edited: Rik
on 15 Nov 2025 at 19:11
You have the bottom and top points in a resolution you can specify. That means you can generate a list of triangular faces (remember: every trapezoid can be split into 2 triangles). If you treat your list of points as list of vertices and define the faces as indices into that list of vertices, you are at the definition the patch function expects.
Did you try something like this yet?
I admit you would expect the surface function to do this (or actually surf), which is why my comment first referred to that function instead.
Accepted Answer
Paul
on 15 Nov 2025 at 19:52
Hi Robert,
Perhaps something like this that draws a pathc between each height line? Salt to taste on the patch command.
Is the f.Color using an undocumented feature?
N=80; % number of angular steps in one rotation
w=7.908e-4; R=6e-4; % constants in equation for p(t) [units=length]
B=0.867; % constant in equation for h(t): h(t)=B*p(t) [dimensionless]
dt=2*pi/N; % angle step size [radians]
t=(0:dt:2*pi)'; % angle of rotation (vector, length N+1) [radians]
p=((w/2)*cos(t)+(R^2*(sin(t).^2+0.5*cos(t).^2)-(w^2/2)*sin(t).^2).^0.5)./(sin(t).^2+0.5*cos(t).^2);
% Compute h(t):
h=B*p;
% Compute arrays of 3D points
pt=[p.*cos(t),p.*sin(t),h/2]; % x,y,z coords of points along top of shape
pb=[p.*cos(t),p.*sin(t),-h/2]; % x,y,z coords of points along bottom of shape
figure
view(40,60);
hold on;
axis equal;
for i=1:N+1
% Draw HEIGHT LINES between top and bottom points
f=plot3([pt(i,1),pb(i,1)],...
[pt(i,2),pb(i,2)],...
[pt(i,3),pb(i,3)],LineWidth=4);
f.Color = [0,0.7,0.7,0.7]; % four-element color?
if i <= N
patch(...
[pt(i,1),pb(i,1),pb(i+1,1),pt(i+1,1)],...
[pt(i,2),pb(i,2),pb(i+1,2),pt(i+1,2)],...
[pt(i,3),pb(i,3),pb(i+1,3),pt(i+1,3)],...
'r','FaceColor',[0,0.7,0.7],'EdgeColor','None','FaceAlpha',0.7);
end
drawnow;
end
3 Comments
Paul
on 15 Nov 2025 at 21:42
Just to make sure we're on the same page, the surface isn't really smooth because each patch is a plane. Viewing zoomed in from above makes the transitions at the vertices evident. But maybe it's smooth enough.
N=80; % number of angular steps in one rotation
w=7.908e-4; R=6e-4; % constants in equation for p(t) [units=length]
B=0.867; % constant in equation for h(t): h(t)=B*p(t) [dimensionless]
dt=2*pi/N; % angle step size [radians]
t=(0:dt:2*pi)'; % angle of rotation (vector, length N+1) [radians]
p=((w/2)*cos(t)+(R^2*(sin(t).^2+0.5*cos(t).^2)-(w^2/2)*sin(t).^2).^0.5)./(sin(t).^2+0.5*cos(t).^2);
% Compute h(t):
h=B*p;
% Compute arrays of 3D points
pt=[p.*cos(t),p.*sin(t),h/2]; % x,y,z coords of points along top of shape
pb=[p.*cos(t),p.*sin(t),-h/2]; % x,y,z coords of points along bottom of shape
figure
view(40,60);
hold on;
axis equal;
for i=1:N
% change edge color for this view
patch(...
[pt(i,1),pb(i,1),pb(i+1,1),pt(i+1,1)],...
[pt(i,2),pb(i,2),pb(i+1,2),pt(i+1,2)],...
[pt(i,3),pb(i,3),pb(i+1,3),pt(i+1,3)],...
'r','FaceColor',[0,0.7,0.7],'EdgeColor','k','FaceAlpha',0.7);
end
view(2)
axis([14,17,-2,2]*1e-4)
The four element Color "property" is undocumented AFAIK. line doesn't have a FaceAlpha or Alpha property.
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
