3D空间中的曲线拟合点
尝试找到可以帮助我们通过一系列点绘制 3D 线的函数。
对于我们知道的每个点:日期和时间、纬度、经度、高度、速度和航向。 数据可能每 10 秒记录一次,我们希望能够估计之间的点并将粒度增加到 1 秒。从而在 3D 空间中创建虚拟飞行路径。
我发现了许多曲线拟合算法,它们可以近似通过一系列点的直线,但它们不能保证这些点相交。它们也不考虑速度和航向来确定物体到达下一个点最有可能采取的路径。
Trying to find functions that will assist us to draw a 3D line through a series of points.
For each point we know: Date&Time, Latitude, Longitude, Altitude, Speed and Heading.
Data might be recorded every 10 seconds and we would like to be able to guestimate the points in between and increase granularity to 1 second. Thus creating a virtual flight path in 3D space.
I have found a number of curve fitting algorithms that will approximate a line through a series of points but they do not guarantee that the points are intersected. They also do not take into account speed and heading to determine the most likely path taken by the object to reach the next point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从物理学的角度来看:
您必须假设中间点的加速度才能获得插值。
如果您的物理系统表现相对良好(如汽车或飞机),而不是弹跳球,您可以继续假设加速度随点之间的时间线性变化。
恒定变化的加速运动的矢量方程为:
其中除 t 之外的所有大小都是矢量。
对于每个段,您已经知道 v(t=t0) x(t=t0) tfinal 和 x(tfinal) v(tfinal)
通过求解微分方程,您将得到:
并对位置和速度施加初始和最终约束,您将得到:
等式 2:
因此,将等式 2 的值插入等式 1 中,您将获得基于初始和最终位置以及速度的点的时间插值。
哈!
编辑
一些二维速度突然变化的示例(在 3D 中完全相同)。如果初始速度和最终速度相似,您将获得“更直”的路径。
假设:
如果
这是一个动画,您可能会看到速度从 V0 = {0, 1} 开始变化至 Vf = {1, 5}:
在这里,您可能会看到一个 3D 加速体,其位置以相等的间隔进行:
编辑
一个完整的问题:
为了方便起见,我将在笛卡尔坐标中工作。如果您想从 lat/log/alt 转换为笛卡尔坐标系,只需执行以下操作:
其中 phi 是经度,theta 是纬度,而 rho 是您的海拔高度加上地球半径。
因此,假设我们的线段开始于:
结束于:
我明确地对坐标原点进行了更改,以将原点设置为我的起点。这只是为了获得漂亮的整数......
所以我们将这些数字替换为a和b的公式中并得到:
用这些我们进入等式1,物体的位置由下式给出:
就是这样。将 t 替换为上面等式中的值,即可得到 1 到 10 秒的位置。
动画运行:
编辑 2
如果您不想弄乱垂直方向加速度(也许因为你的“速度计”没有读取它),你可以为 z 轴分配一个恒定的速度(考虑它平行于 Rho 轴有一个非常小的错误),等于(Zfinal - Zinit) /(Tf-T0),然后解决飞机上忘记高度的问题。
From a physics viewpoint:
You have to assume something about the acceleration in your intermediate points to get the interpolation.
If your physical system is relatively well-behaved (as a car or a plane), as opposed to for example a bouncing ball, you may go ahead supposing an acceleration varying linearly with time between your points.
The vector equation for a constant varying accelerated movement is:
where all magnitudes except t are vectors.
For each segment you already know v(t=t0) x(t=t0) tfinal and x(tfinal) v(tfinal)
By solving the differential equation you get:
And imposing the initial and final contraints for position and velocity you get:
Eqs 2:
So inserting the values for eqs 2 into eq 1 you get the temporal interpolation for your points, based on the initial and final position and velocities.
HTH!
Edit
A few examples with abrupt velocity change in two dimensions (in 3D is exactly the same). If the initial and final speeds are similar, you'll get "straighter" paths.
Suppose:
If
Here is an animation where you may see the speed changing from V0 = {0, 1} to Vf = {1, 5}:
Here you may see an accelerating body in 3D with positions taken at equal intervals:
Edit
A full problem:
For convenience, I'll work in Cartesian coordinates. If you want to convert from lat/log/alt to Cartesian just do:
Where phi is the longitude, theta is the latitude, and rho is your altitude plus the radius of the Earth.
So suppose we start our segment at:
and end at
I clearly made a change in the origin of coordinates to set the origin at my start point. That is just for getting nice round numbers ...
So we replace those numbers in the formulas for a and b and get:
With those we go to eq 1, and the position of the object is given by:
And that is it. You get the position from 1 to 10 secs replacing t by its valus in the equation above.
The animation runs:
Edit 2
If you don't want to mess with the vertical acceleration (perhaps because your "speedometer" doesn't read it), you could just assign a constant speed to the z axis (there is a very minor error for considering it parallel to the Rho axis), equal to (Zfinal - Zinit)/(Tf-T0), and then solve the problem in the plane forgetting the altitude.
您要问的是一般插值问题。我的猜测是,您的实际问题不是由于使用了曲线拟合算法,而是由于您将其应用于系统记录的所有离散值而不是相关的值集。
让我们分解一下你的问题。您当前正在球面映射的 3D 空间中绘制一个点,并调整线性和曲线路径。如果我们离散化具有六个自由度的对象执行的操作(滚动、俯仰和偏航),您特别感兴趣的唯一操作是线性路径和曲线路径,以说明任何方向的俯仰和偏航。 基础物理学,也可以考虑加速和减速。
如果了解 映射很容易。只需相对于平面上的位置展开点,调整纬度、经度和高度即可。这应该允许您展平原本沿着弯曲路径存在的数据,尽管这对于解决您的问题可能并不是严格必要的(见下文)。
线性插值很容易。给定时间上向后的任意数量的点,这些点符合系统确定的 n 误差范围内的直线,*构造直线并计算每个点之间的时间距离。从这里开始,尝试将时间点拟合为两种情况之一:恒定速度或恒定加速度。
曲线插值有点困难,但仍然合理。对于俯仰、偏航或俯仰+偏航组合的情况,构建一个包含时间上向后任意数量的点的平面,系统的曲线读数误差在 m 以内。* 根据这些数据,构建一个平面曲线并再次考虑恒定速度或沿曲线的加速度。
您可以通过尝试预测飞行中飞机的预期操作作为决策树或神经网络相对于飞行路径的一部分来做得更好。我将把它作为练习留给读者。
祝您设计系统好运。
--
* 根据问题描述,两个错误读数均应来自 GPS 数据。对这些数据中的错误进行核算和调整是一个单独的有趣问题。
What you're asking is a general interpolation problem. My guess is your actual problem isn't due to the curve-fitting algorithm being used, but rather your application of it to all discrete values recorded by the system instead of the relevant set of values.
Let's decompose your problem. You're currently drawing a point in spherically-mapped 3D space, adjusting for linear and curved paths. If we discretize the operations performed by an object with six degrees of freedom (roll, pitch, and yaw), the only operations you're particularly interested in are linear paths and curved paths accounting for pitch and yaw in any direction. Accounting for acceleration and deceleration also possible given understanding of basic physics.
Dealing with the spherical mapping is easy. Simply unwrap your points relative to their position on a plane, adjusting for latitude, longitude, and altitude. This should allow you to flatten data that would otherwise exist along a curved path, though this may not strictly be necessary for the solutions to your problem (see below).
Linear interpolation is easy. Given an arbitrary number of points backwards in time that fit a line within n error as determined by your system,* construct the line and compute the distance in time between each point. From here, attempt to fit the time points to one of two cases: constant velocity or constant acceleration.
Curve interpolation is a little more difficult, but still plausible. For cases of pitch, yaw, or combined pitch+yaw, construct a plane containing an arbitrary number of points backwards in time, within m error for curved readouts from your system.* From these data, construct a planar curve and once again account for constant velocity or acceleration along the curve.
You can do better than this by attempting to predict the expected operations of a plane in flight as part of a decision tree or neural network relative to the flight path. I'll leave that as an exercise for the reader.
Best of luck designing your system.
--
* Both error readouts are expected to be from GPS data, given the description of the problem. Accounting and adjusting for errors in these data is a separate interesting problem.
您需要的是(而不是对物理进行建模)通过数据拟合样条线。我使用了一本数字食谱书(http://www.nrbook.com/a 有免费的 C 和 FORTRAN查看 F77 第 3.3 节以获得所需的数学知识)。如果你想简单一点,那么只需拟合穿过点的线,但这根本不会产生平滑的飞行路径。时间将是您的
x
值,记录的每个参数都将具有其自己的三次样条参数。因为我们喜欢这个问题的长帖子,所以这里是完整的代码:
//驱动程序
//三次样条定义
What you need (instead of modeling the physics) is to fit a spline through the data. I used a numerical recipies book (http://www.nrbook.com/a has free C and FORTRAN algorithms. Look into F77 section 3.3 to get the math needed). If you want to be simple then just fit lines through the points, but that will not result in a smooth flight path at all. Time will be your
x
value, and each parameter loged will have it's own cublic spline parameters.Since we like long postings for this question here is the full code:
//driver program
// Cubic spline definition
您可以使用霍夫变换算法找到与 3d 和 2d 空间中的点相交的直线的近似值。我只熟悉它在 2d 中的用途,但它仍然适用于 3d 空间,因为你知道你正在寻找什么样的线。有一个链接的基本实现描述。您可以通过 Google 搜索预制版本,这里有一个 2d C 实现 CImg 的链接。
算法过程(大致)...首先,您找到您认为最能近似直线形状的直线方程(二维抛物线、对数、指数等)。您采用该公式并求解其中一个参数。
变为
下一步,对于您尝试匹配的每个点,将这些点插入 y 和 x 值。有了 3 个点,就可以得到 b 相对于 a 的 3 个独立函数。
接下来,理论是,您会找到穿过每个点的所有可能的线,对于每个单独的点来说,这些线是无限多的,但是当组合在累加器空间中时,只有几个可能的参数最适合。实际上,这是通过选择参数的范围空间(我选择 -2 <= a <= 1, 1 <= b <= 6)并开始插入变量参数的值来完成的为对方解决。您可以计算累加器中每个函数的交集数。具有最高值的点为您提供参数。
处理后的累加器
b = 3 - 2a
处理后的累加器
b = 1 - 4a
处理后的累加器
b = -5 - 10a
参数设置为最高累积值是
(ba) = (5 -1)
,最适合给定点的函数是y = 5 - x
。祝你好运。
You can find an approximation of a line that intersects points in 3d and 2d space using a Hough Transformation algorithm. I am only familiar with it's uses in 2d however but it will still work for 3d spaces given that you know what kind of line you are looking for. There is a basic implementation description linked. You can Google for pre-mades and here is a link to a 2d C implementation CImg.
The algorithm process (roughly)... First you find equation of a line that you think will best approximate the shape of the line (in 2d parabolic, logarithmic, exponential, etc). You take that formula and solve for one of the parameters.
becomes
Next, for each point you are attempting to match, you plugin the points to the y and x values. With 3 points, you would have 3 separate functions of b with respect to a.
Next, the theory is that you find all possible lines which pass through each of the points, which is infinitely many for each individual point however when combined in an accumulator space only a few possible parameters best fit. In practice this is done by choosing a range space for the parameters (I chose -2 <= a <= 1, 1 <= b <= 6) and begin plugging in values for the variant parameter(s) and solving for the other. You tally up the number of intersections from each function in an accumulator. The points with the highest values give you your parameters.
Accumulator after processing
b = 3 - 2a
Accumulator after processing
b = 1 - 4a
Accumulator after processing
b = -5 - 10a
The parameter set with the highest accumulated value is
(b a) = (5 -1)
and the function best fit to the points given isy = 5 - x
.Best of luck.
我的猜测是,严肃的应用程序将使用 http://en.wikipedia.org/wiki/Kalman_filter 。顺便说一句,这可能也不能保证报告的点相交,除非您稍微修改一下参数。它期望给定的每个数据点都存在某种程度的错误,因此它认为对象在时间 T 的位置不一定是它在时间 T 的位置。当然,您可以设置错误分布来表示您是绝对确定你知道它在时间 T 的位置。
如果不使用卡尔曼滤波器,我会尝试将其转化为优化问题。以 1s 粒度工作并写下等式
x_t' = x_t + (Vx_t + Vx_t')/2 + e,
Vx_t_报告 = Vx_t + f,
Vx_t' = Vx_t + g
其中 e、f 和 g 代表噪声。然后创建一个惩罚函数,例如 e^2 + f^2 + g^2 +...
或一些加权版本,例如 1.5e^2 + 3f^2 + 2.6g^2 +... 根据您对错误的真正含义以及您想要的答案的平滑程度的想法,并找到使惩罚函数尽可能小 - 如果方程结果良好,则使用最小二乘。
My guess is that a serious application of this would use a http://en.wikipedia.org/wiki/Kalman_filter. By the way, that probably wouldn't guarantee that the reported points were intersected either, unless you fiddled with the parameters a bit. It would expect some degree of error in each data point given to it, so where it thinks the object is at time T would not necessarily be where it was at time T. Of course, you could set the error distribution to say that you were absolutely sure you knew where it was at time T.
Short of using a Kalman filter, I would try and turn it into an optimisation problem. Work at the 1s granularity and write down equations like
x_t' = x_t + (Vx_t + Vx_t')/2 + e,
Vx_t_reported = Vx_t + f,
Vx_t' = Vx_t + g
where e, f, and g represent the noise. Then create a penalty function such as e^2 + f^2 + g^2 +...
or some weighted version such as 1.5e^2 + 3f^2 + 2.6g^2 +... according to your idea of what the errors really are and how smooth you wnat the answer to be, and find the values that make the penalty function as small as possible - with least squares if the equations turn out nicely.