How to apply any 2D lines on to a given 3D surface?

1 view (last 30 days)
I will be given the dimension of a few lines on a 2D plane. I want to be able to apply them on any 3D curved surface made of a set of data points. It surface can be a set of data in a point cloud. This surface may not be represented by any equations. I just want to know if there is a way to fit these lines on to a surface and now the lines will have a curve based on that surface.
  1 Comment
Matt J
Matt J on 2 Nov 2022
To me at least, the question is not clear enough to be answered. Please provide an example set of input data and some description of what form the output should take.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 2 Nov 2022
Edited: Star Strider on 2 Nov 2022
This is actually straightforward with the griddedInterpolant function, providing the data are gridded to begin with. The surface can actually be random, since the funciton will interpolate essentially anything it is given. The llines to be drawn on the surface have to have enough data points to fit any of the surface irregularities.
Here, the black ine is straight and the magenta line is a sine curve —
x = linspace(-5, 5, 20);
y = linspace(0, 10, 25);
[X,Y] = ndgrid(x,y);
z = randn(20, 25);
F = griddedInterpolant(X,Y,z);
x1v = linspace(-2, 3.5, 1500);
y1v = linspace(3, 7, 1500);
z1v = F(x1v,y1v);
x2v = linspace(-4, 4, 2500);
y2v = 4+2*sin(2*pi*x2v/5);
z2v = F(x2v,y2v);
figure
surf(x, y, z.')
hold on
plot3(x1v, y1v, z1v, 'k', 'LineWidth',3)
plot3(x2v, y2v, z2v, 'm', 'LineWidth',3)
hold off
grid on
xlabel('X')
ylabel('Y')
view(35,80)
The griddedInterpolant funciton would have fewer problems with a more regular surface. The number of data points in the lines is important in order to provide the function with good enough resolution to map all the irregularities. I gave it a real challenge here, and it seems to have done quite well.
EDIT — Aesthetic fix.
.
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!