代码之家  ›  专栏  ›  技术社区  ›  M.Thomas

在Matlab中给定弧长和方向/角度的曲面上查找点

  •  4
  • M.Thomas  · 技术社区  · 10 年前

    我需要使用Matlab在曲面上找到一个弧长为给定值的点(给定相对于起点的角度)。

    假设我有一个高阶曲面,其中z=f(x,y),它是使用Matlabs拟合函数从采样点拟合的。如果我有一个起点,假设a=(x_0,y_0,f(x_0,y_0)),并想知道在xy平面上用户定义的角度θ处沿着该曲面的一个点的坐标,以便曲面上覆盖的距离为给定值,例如10mm。

    我想我需要做的是解决这个问题 equation 对于b的值,我们知道a、s和函数定义曲面。但我不知道如何在Matlab中写这个。我假设我需要使用Matlab中的求解函数。

    如果您能在Matlab中以最有效的形式编写这篇文章,我们将不胜感激!

    1 回复  |  直到 10 年前
        1
  •  0
  •   Ander Biguri    10 年前

    这里是一个假设 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');
    

    enter image description here


    可视化代码

    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)