Search for a point on the surface based on the length of the arc and direction / angle in Matlab

I need to find a point on the surface (given by the angle relative to the starting point), where the length of the arc is the given value using Matlab.

Let's say that I have a high order surface, where z = f (x, y), which was set from sample points using the Matlabs fit function. If I have a starting point, say a = (x_0, y_0, f (x_0, y_0)) and want to know the coordinate of the point along this surface with a user-defined angle in the xy plane, so the distance traveled over the surface is a given value, for example 10 mm

I assume that I need to solve this equation for the value of b, since we know that a, s and the function that defines the surface, But I'm not sure how to write this in Matlab. I assume that I need to use the solution function in Matlab.

Any help on how to write this in Matlab and in the most efficient way would be greatly appreciated!

+4
source share
1 answer

Here is an example, assuming dx=1, dy=1the inclusion of arbitrary step size x and y should not be difficult

% //I am assuming here that you know how to get your Z
z=peaks(60); 
% //start point
spoint=[30,30];
% //user given angle
angle=pi/4;
% // distance you want
distance=10;
%// this is the furthes the poitn can be
endpoint=[spoint(1)+distance*cos(angle) spoint(2)+distance*sin(angle)]; 

%// we will need to discretize, so choose your "accuracy"
npoints=100;
%//compute the path integral over the line defined by startpoitn and endpoint
[cx,cy,cz]=improfile(z,[spoint(1) endpoint(1)],[spoint(2) endpoint(2)],npoints);

% // this computes distances between adjacent points and then computes the cumulative sum
dcx=diff(cx);
dcy=diff(cy);
dcz=diff(cz);

totaldist=cumsum(sqrt(dcx.^2+dcy.^2+dcz.^2));
%// here it is! the last index before it gets to the desired distance
ind=find(totaldist<distance,1,'last');

enter image description here


Visualization code

imagesc(z);axis xy;colormap gray
hold on;
plot(spoint(1),spoint(2),'r.','markersize',10)
plot(endpoint(1),endpoint(2),'r*','markersize',5)
plot([spoint(1) endpoint(1)],[spoint(2) endpoint(2)],'b')
plot(cx(ind),cx(ind),'g*','markersize',10)
0
source

Source: https://habr.com/ru/post/1627322/


All Articles