Filter löschen
Filter löschen

How to project a line on a surface?

32 Ansichten (letzte 30 Tage)
Sachal Hussain
Sachal Hussain am 9 Nov. 2021
Kommentiert: Sachal Hussain am 15 Nov. 2021
Hi,
I am plotting a 3D surface and a straight line together. The line is not on the surface nor intersecting the surface. Now I want to project that line onto the surface.
Anyone can help me how to do this?
Thank you!
  2 Kommentare
Sargondjani
Sargondjani am 9 Nov. 2021
What is the shape of your surface? Is it a function? And how do you want to project it?
I assume your surface consists of a finite number of data points, and you use vertical projection. You could use interpolation to let the line closely follow the surface. Assume your surface consists of vectors X,Y,Z
If the line consists of a vectors with x,y coordinates in pairs xp, yp, you could do:
F=scatteredInterpolant(X,Y,Z);
Proj_line = F(xp,yp);
Otherwise you could try to change your data to something like this.
Sachal Hussain
Sachal Hussain am 10 Nov. 2021
It's an anatomical shape, not a function. The line is above the surface so I want to project it straight down on the surface.
The line is plotted in a space so it has X,Y,Z coordinates.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 10 Nov. 2021
Let X, Y, Z be your surface data. And (x,y) be the coordinates of the line data. Use interpolation to get the z values of line from surface and then plot.
z = interp2(X,Y,Z,x,y) ;
surf(X,Y,Z)
shading interp
plot3(x,y,z,'r')
  3 Kommentare
KSSV
KSSV am 10 Nov. 2021
Let X, Y, Z be your column data.
F=scatteredInterpolant(X,Y,Z) ;
z=F(x, y) ;
Sachal Hussain
Sachal Hussain am 15 Nov. 2021
I tried to follow your suggested way but the result is still not correct. Below is the code I wrote, Please have a look and point out where I am doing wrong. Thak you!
import_stl = stlread('mesh_40_tagli.stl');
figure,hold on,trisurf(import_stl, 'FaceColor','flat', 'LineStyle', 'none');view(3),
% Adding noise to x,y,z coordinates of surface to make them 'unique'
a = import_stl.Points(:,1); t = a == unique(a)'; out1 = sum(cumsum(.0001*t).*t,2)-.0001 + a; % x-coordinates
a = import_stl.Points(:,2); t = a == unique(a)'; out2 = sum(cumsum(.0001*t).*t,2)-.0001 + a; % y-coordinates
a = import_stl.Points(:,3); t = a == unique(a)'; out3 = sum(cumsum(.0001*t).*t,2)-.0001 + a; % z-coordinates
X = [133.4843 131.3938]; Y = [70.1121 66.5661]; Z = [51.3541 27.6482]; % query points
xq = linspace(X(1),X(2),50); yq = linspace(Y(1),Y(2),50); % sampling of query points
F=scatteredInterpolant(out1,out2,out3) ;
zq=F(xq,yq) ;
plot3(xq,yq,zq);

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by