二维插值算法

发布于 2024-08-25 02:59:49 字数 170 浏览 10 评论 0原文

我有两个形状,它们是通道的横截面。我想计算两个定义点之间的中间点的横截面。 在这种情况下使用的最简单(相对简单?)的算法是什么?

PS:我遇到过一些算法,比如自然邻域和泊松,看起来很复杂。我正在寻找一个简单的解决方案,可以快速实施。

编辑:我从标题中删除了“最简单”一词,因为它可能会产生误导

I have two shapes which are cross sections of a channel. I want to calculate the cross section of an intermediate point between the two defined points.
What's the simplest (relatively simple?) algorithm to use in this situation?

P.S.: I came across several algorithms like natural neighbor and poisson, which seemed complex. I'm looking for a simple solution, which could be implemented quickly.

EDIT: I removed the word "Simplest" from the title since it might be misleading

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如若梦似彩虹 2024-09-01 02:59:49

这很简单:

  1. 在每个横截面上沿着横截面的边界以均匀间隔绘制 N 个点。
  2. 从横截面 1 上的第 n 个点到横截面 2 上的第 n 个点绘制直线。
  3. 在旧横截面之间的所需距离处取下新横截面。

更简单:

  1. 使用现有的横截面之一而不进行修改。

我想第二个建议可能太简单了,但我敢打赌没有人提出更简单的建议!

编辑以下OP的评论:(太多的重新评论)

好吧,你确实要求一个简单的方法!我不确定第一种方法是否存在与您相同的问题。如果横截面不是太奇怪(如果它们是凸多边形,则可能是最好的)并且您没有做任何奇怪的事情,例如将一个横截面的左侧映射到另一个横截面的右侧(从而迫使大量交叉线)那么该方法应该产生某种合理的横截面。在您建议使用三角形和矩形的情况下,假设三角形位于其底部,一个顶点位于顶部。将该点映射到矩形的左上角,然后沿着连接相应点的两个横截面的边界沿相同方向(顺时针或逆时针)前进。我没有看到任何交叉线,并且在两个横截面之间的任何距离处都看到了明确的形状。

This is simple:

  1. On each cross section draw N points at evenly spaced intervals along the boundary of the cross-section.
  2. Draw straight lines from the n-th point on cross-section 1 to the n-th point on cross-section 2.
  3. Take off your new cross-section at the desired distance between the old cross-sections.

Simpler still:

  1. Use one of the existing cross-sections without modification.

This second suggestion might be too simple I suppose, but I bet no-one suggests a simpler one !

EDIT following OP's comment: (too much for a re-comment)

Well, you did ask for a simple method ! I'm not sure I see the same problem with the first method as you do. If the cross sections are not too weird (probably best if they are convex polygons) and you don't do anything strange such as map the left side of one cross-section to the right side of the other (thereby forcing lots of crossing lines) then the method should produce some kind of sensible cross section. In the case you suggest of a triangle and a rectangle, suppose the triangle is sitting on its base, one vertex at the top. Map that point to, say, the top left corner of the rectangle, then proceed in the same direction (clockwise or anti-clockwise) around the boundaries of both cross-sections joining corresponding points. I don't see any crossing lines, and I see a well-defined shape at any distance between the two cross-sections.

怂人 2024-09-01 02:59:49

请注意,高性能马克的答案存在一些含糊之处,您可能需要解决这些问题,并将定义他的方法的输出质量。最重要的是,当你在两个横截面上画n个点时,你确定它们之间是什么样的对应关系,也就是说,如果你按照High Performance Mark建议的方式这样做,那么标记点的顺序变得很重要。

我建议同时旋转(正交)平面穿过两个横截面,然后在一个横截面上与该平面相交的一组点只需与在另一个横截面上与该平面相交的一组点相匹配。假设,这些集合中的点的数量没有限制,但它确实降低了原始情况下对应问题的复杂性。

Note there are some ambiguities about High Performance Mark's answers you will probably need to address and will define the quality of the output of his method. The most important one is, when you draw the n points on both cross-sections, what sort of correspondence do you determine between them, that is if you do it that way High Performance Mark suggested, then the order of labeling the points becomes important.

I suggest rotating (orthogonal) plane simultaneously through both cross sections, then the set of points which intersect that plane on one cross section just need to be matched to the set of points that intersect that plane on the other cross section. Hypothetically, there is no limit on the number of points in these sets, but it certainly reduces the complexity of the correspondence problem in the original situation.

¢好甜 2024-09-01 02:59:49

这是解决这个问题的另一种尝试,我认为这是一个更好的尝试。

给定两个横截面 C_1C_2

将每个 C_i 放入坐标系 (x,y)< 的全局参考系中/code> 这样它们的相对位置就有意义了。将每个C_i分成上下曲线U_iL_i。这个想法是,您需要将曲线 U_1 连续变形为 U_2,将 L_1 变形为 L_2。 (请注意,如果您愿意,您可以扩展此方法以将每个 C_i 分割为 m 曲线。)

执行此操作的方法如下。对于每个T_i = U_i或L_i采样n点,并确定插值多项式P{T_i}(x)。正如下面有人适当指出的那样,插值多项式很容易受到振荡的影响,尤其是在端点处。可以使用更稳健的最小二乘拟合多项式来代替插值多项式。然后将多项式 P{U_1}(x) = a_0 + a_1 * x + ... + a_n * x^n 变形为 P{U_2}(x) = b_0 + b_1 * x + ... + b_n * x^n as Q{P{U_1},P{U_2}}(x, t) = ( t * a_0 + (1 - t ) b_0 ) + ... + (t * a_n + (1-t) * b_n ) * x^n 其中变形 Q 是在 0<=t<; 上定义的。 =1 其中 t 定义变形所在的点(即在 t=0 处,我们位于 U_2 处,并且位于 < code>t=1 我们位于 U_1 处,并且在每隔一个 t 处我们处于两者的某种连续变形。)
Q{P{L_1},P{L_2}}(x, t) 的情况完全相同。这两种变形在两个横截面之间构造了一个连续的表示,您可以在任何t处进行采样。

请注意,这一切实际上是对两个横截面的插值多项​​式的系数进行线性插值。另请注意,在分割横截面时,您可能应该施加约束,即它们必须在匹配的端点处分割,否则变形中可能会出现“孔”。

我希望这是清楚的。

编辑:解决了插值多项式中的振荡问题。

Here is another try at the problem, which I think is a much better attempt.

Given the two cross-sections C_1, C_2

Place each C_i into a global reference frame with coordinate system (x,y) so that the way they are relatively situated makes sense. Split each C_i into an upper and lower curve U_i and L_i. The idea is going to be that you will want to continuously deform curve U_1 to U_2 and L_1 to L_2. (Note you can extend this method to split each C_i into m curves if you wish.)

The way to do this is as follows. For each T_i = U_i, or L_i sample n points, and determine the interpolating polynomial P{T_i}(x). As some one duly noted below, interpolating polynomials are susceptible to oscillation especially at the endpoints. Instead of the interpolating polynomial, one may instead use the least squares fit polynomial which would be much more robust. Then define the deformation of the polynomial P{U_1}(x) = a_0 + a_1 * x + ... + a_n * x^n to P{U_2}(x) = b_0 + b_1 * x + ... + b_n * x^n as Q{P{U_1},P{U_2}}(x, t) = ( t * a_0 + (1 - t ) b_0 ) + ... + (t * a_n + (1-t) * b_n ) * x^n where the deformation Q is defined over 0<=t<=1 where t defines at which point the deformation is at (i.e. at t=0 we are at U_2 and at t=1 we are at U_1 and at every other t we are at some continuous deformation of the two.)
The exact same follows for Q{P{L_1},P{L_2}}(x, t). These two deformations construct you a continuous representation between the two cross-sections which you can sample at any t.

Note all this is really doing is linearly interpolation the coefficients of the interpolation polynomials of the two pieces of both cross-sections. Note also when spliting the cross-sections you should probably put the constraint that they must be split at end points that match up otherwise you may have "holes" in your deformation.

I hope thats clear.

edit: addressed the issue of oscillation in interpolating polynomials.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文