我需要使用 Matlab 找到曲面上的一个点(给定相对于起点的角度),其中弧长为给定值。
假设我有一个高阶曲面,其中 z=f(x,y),它是使用 Matlabs 拟合函数从采样点拟合的。如果我有一个起点,假设 a = (x_0, y_0, f(x_0,y_0)) 并想知道沿该表面以用户定义的角度 theta 远离 xy 平面的点的坐标,以便覆盖的距离表面上是给定值,例如10毫米。
我假设我需要做的是解决这个 的 b 值,假设我们知道 a、s 和定义表面的函数。但我不确定如何在 Matlab 中编写这个。我假设我需要使用 Matlab 中的求解函数。
任何关于如何在 Matlab 中以最有效的形式编写此代码的帮助将不胜感激!
这里是一个例子,假设
dx=1
,dy=1
,合并任意x和y步长应该不难
% //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');
可视化代码
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)