Hello Sachal,
I understand that you have a surface plot with two points, and you want to connect the two points with a line that fits the surface.
Assuming that you have the equation that describes the surface, a workflow to achieve this would be as follows:
- Generate a plane that passes through the points
- Find the points of intersection of the plane and the surface
- Plot the points of intersection
I am using an ellipsoid as an example for the surface. The figure below shows the ellipsoid with the points.
Using the function “plot3” connects the points with a straight line as shows below
Following the steps mentioned, we generate a plane that passes through the points
The next step is to find the points of intersection of the plane and the surface.
We do this by finding all the points of on the plane that satisfy the equation of the ellipsoid.
Finally, we plot the points of intersection of the ellipsoid and the plane.
The figure below shows the plot without the plane
Below is the MATLAB code for the entire process
[X,Y,Z] = ellipsoid(10,10,10,20,10,10,50);
plot3(x,y,z,"r-*", "LineWidth", 2, "MarkerSize",10)
xPlane = meshgrid(linspace(x(1), x(end), 500));
yPlane = meshgrid(linspace(y(1), y(end), 500));
zPlane = meshgrid(linspace(z(1), z(end), 500))';
surface = surf(xPlane,yPlane,zPlane);
surface.FaceColor = [0 0.5 0.3];
inside = ((xPlane-10)/20).^2 + ((yPlane-10)/10).^2 + ((zPlane-10)/10).^2 - 1;
isect_x = xPlane(abs(inside) < threshold);
isect_y = yPlane(abs(inside) < threshold);
isect_z = zPlane(abs(inside) < threshold);
plot3(isect_x, isect_y, isect_z, 'm-', "LineWidth",2);
You can refer to the link below for more information on generating grid for plotting the plane
- meshgrid: https://www.mathworks.com/help/releases/R2021a/matlab/ref/meshgrid.html?&s_tid=doc_srchtitle
Thank You,
Gautam Murthy