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

21 Ansichten (letzte 30 Tage)
Mohamed Ibraheem
Mohamed Ibraheem am 28 Dez. 2021
Beantwortet: Adam Danz am 28 Dez. 2021
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.

Akzeptierte Antwort

Adam Danz
Adam Danz am 28 Dez. 2021
> 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)

Weitere Antworten (1)

DGM
DGM am 28 Dez. 2021
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)

Kategorien

Mehr zu Thermal Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by