【问题标题】:Finding a point on a surface given an arc length and direction/angle in Matlab在 Matlab 中找到给定弧长和方向/角度的曲面上的点
【发布时间】:2016-05-14 08:21:25
【问题描述】:

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

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

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

任何有关如何在 Matlab 中以最有效的形式编写此代码的帮助将不胜感激!

【问题讨论】:

  • 听起来是个棘手的任务。该表面是如何定义的? (您有示例吗?)我认为您必须沿途添加积分/总和(如果由于离散步骤而无法积分)距离。至少您知道重点在(x_0, y_0)(x_0+cos(theta)*r, y_0+sin(theta)*r) 之间,并且您可以在达到r 时停止积分/求和。
  • 当你说任意角度时,你的意思是用户指定的?
  • 嗨,我的回答有效吗?您需要更多帮助吗?
  • 谢谢安德,我使用了基于你的方法! (抱歉这么久才回复)。

标签: matlab integration differential-equations


【解决方案1】:

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

【讨论】:

  • 好主意。 :P spoint(1)+distance*sin(angle) 可能应该被编入索引 spoint(2)?
  • @MatthiasW。确实!刚发帖才看到你的评论,之前都没看!很高兴知道我们在同一个页面(这意味着这并不疯狂)
  • 感谢安德的回答。我过去曾使用过类似的 a 方法,但希望有一个更封闭的形式解决我的问题(但也许这是不可能的),以在我必须为数千个其他点做这件事时加快这个过程。一个问题,你为什么使用 improfile 功能?
  • 封闭形式的定义是能够将您的函数f(x,y) 分析集成到您的路径上。显然,对于任意的f,该解决方案不存在,因为在多种情况下无法进行分析。所以 naswer 是否定的,任意的f 没有封闭形式。我使用了improfile,因为它可用并且非常好地集成在用户指定的路径上。@M.Thomas
猜你喜欢
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多