How to project a line on a surface?
32 views (last 30 days)
Show older comments
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795554/image.jpeg)
2 Comments
Sargondjani
on 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.
Answers (1)
KSSV
on 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 Comments
KSSV
on 10 Nov 2021
Let X, Y, Z be your column data.
F=scatteredInterpolant(X,Y,Z) ;
z=F(x, y) ;
See Also
Categories
Find more on NaNs 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!