# Retrieve orthogonal coordinate curves from interpolated surface

43 views (last 30 days)
Dimitrii Nikolaev on 23 Jul 2021
Commented: Dimitrii Nikolaev on 11 Aug 2021
Problem:
I'm trying to generate a pattern, which is well definable in cartesian coordinates on some curved survace, while longitudinal characteristics of the pattern would be preserved. (One could think for example on engraving a text on some surface)
EXAMPLE (straight line l=1 on the surface):
Assume a generic Spline-fitted surface
(for example, surface fit from spap2 documentation):
%% surface fit example spap2
x = -2:.2:2;
y = -1:.25:1;
[xx, yy] = ndgrid(x,y);
z = exp(-(xx.^2+yy.^2));
figure
sp = spap2({augknt([-2:2],3),augknt([-2:2],3)},8,{x,y},z);
fnplt(sp)
Result of the surface fit with spap2 allows us now to interpolate the cartesian z coordinate on the surface by calling fnval.
Line on this surface
Now let's define a straight line [0 0.5] -> [1 0.5] with length of 1 in cartesian xy coordinates, interpolate the z-coordinate and plot it in the same figure
%% plot line on the surface
hold on
lin_x = linspace(0,1,30);
lin_y = linspace(.5,.5,30);
lin_z = fnval(sp,[lin_x;lin_y]);
plot3(lin_x,lin_y,lin_z,'r','LineWidth',2)
Both code section above results in following: This line have a length of 1 only if z0->z1 is a straight line.
The possibility to define some line with a specific length in such plane woud be to use curvilinear coordinates where instead of straight orthogonal x and y vectors, (orthogonal) curves x(u) and y(v) are used, where u and v represent the distance along the x and y curve
Question:
how to use curvilinear coordinates properly under these circumstances?
What would be the best way to retrieve a set of orthogonal coordinate curves for describing coordinates in this plane in a curvilinear manner?
An approach I'm currently thinking about would be:
1. Consider some origin point O on the plane
2. Consider direction of the first coordinate curve x(u) in cartesian coordinates
3. Sample a set of points in cartesian X0-plane from surface. fit a spline or use directly as linear interpolated curve
4. Interpolate a point x(1) along this curve exactly 1 unit away from origin e.g. by using interparc
5. Estimate the normal vector n to the surface on point x(1)
6. compute orthogonal direction for y(v) as cross product from x(u) and n
7. Sample a set of points in cartesian plane (where the curve O->y(v) is located) from surface. fit a spline or use directly as linear interpolated curve
8. repeat Steps 4-7 for points between x(0) y(0) and x(1) y(1) for z-interpolation and plotting
However i'm not sure if I'm reinventing a bicycle rigth now and if there is some more elegant solution for 3D curvilinear coordinates in MATLAB.
Thanks for any Valuable input and considaretions in Advance!
##### 2 CommentsShowHide 1 older comment
Dimitrii Nikolaev on 11 Aug 2021
@darova: well, for example I would like to describe two orthogonal lines with letgth of 1 unit along the surface and a circle, with opposite points on the surface exactly 1 unit far away from each other. Like that:  Please note: Of course all lengths slightly differ from 1, as I'm am unable to achieve my goal so far.
You can reproduce these plots using following code:
%% plot X-line on the surface
hold on
lin_x = linspace(0,1,30);
lin_y = linspace(0,0,30);
lin_z = fnval(sp,[lin_x;lin_y]);
plot3(lin_x,lin_y,lin_z,'r','LineWidth',2)
%% plot Y-line on the surface
hold on
lin_x = linspace(0,0,30);
lin_y = linspace(0,1,30);
lin_z = fnval(sp,[lin_x;lin_y]);
plot3(lin_x,lin_y,lin_z,'g','LineWidth',2)
%% plot circle of d = 1 with centre in .5 .5
r =.5 ;alpha = linspace(0,2*pi,30);
circ_x = r*cos(alpha)+.5;
circ_y = r*sin(alpha)+.5;
circ_z = fnval(sp,[circ_x;circ_y]);
plot3(circ_x,circ_y,circ_z,'y:','LineWidth',2)

R2021a

### Community Treasure Hunt

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

Start Hunting!