How to project and fit a 2D path onto a 3D surface?

25 ビュー (過去 30 日間)
Mohamed Ibraheem
Mohamed Ibraheem 2021 年 12 月 28 日
回答済み: Adam Danz 2021 年 12 月 28 日
I want to project a 2D spiral path on a 3D surface as in the attached image. How can this be done? Any help would be appreciated.

採用された回答

Adam Danz
Adam Danz 2021 年 12 月 28 日
> I want to project a 2D spiral path on a 3D surface
Inputs:
  • (x,y) coordinates of the 2D spiral
  • (X,Y,Z) coordinates of the 3D surface
Produce 2D spiral.
t = linspace(0,12*pi,201);
x = t/pi.*cos(t);
y = t/pi.*sin(t);
zBase = -8;
z = zBase * ones(size(x));
cla()
plot3(x,y,z, '-', 'Color', [0.5 0.5 0.5])
Produce 3D surface
% Define surface
hold on
[X,Y,Z] = peaks(25);
X = X*4;
Y = Y*4;
% surf(X,Y,Z)
Interpolate the 3D surface so it shares the same x,y grid values as the spiral.
F = griddedInterpolant(X',Y',Z');
[Xq,Yq] = ndgrid(x,y);
Vq = F(Xq,Yq);
% Plot the interpolated surface
surf(Xq,Yq,Vq,'FaceAlpha',.1,'EdgeAlpha',0)
Add the 3D spiral to the surface
z3D = Vq(logical(eye(size(Vq))));
plot3(x,y,z3D, 'k-', 'LineWidth', 1)

その他の回答 (1 件)

DGM
DGM 2021 年 12 月 28 日
Something like
N = 1000;
nturns = 10;
rmax = pi;
zscale = 0.1;
zoffset = 0.5;
r = linspace(0,rmax,N);
th = linspace(0,nturns*2*pi,N);
[x y] = pol2cart(th,r);
z = zoffset + zscale*sin(x);
plot(x,y); hold on
plot3(x,y,z);
view(3)
zlim([0 1])
view(-15,14)

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by