简体   繁体   English

C ++查找点集在其他两个点之间的位置

[英]C++ find where a point set lies between two others

I have three sets of 2d points. 我有三套2d点。 What i need to do is to find out where one sits in relation to the other two. 我需要做的是找出一个相对于其他两个位置。 Every set has the same points, in the same order. 每个集合具有相同的点,并且顺序相同。 One is 'neutral', one is 'max', and the third is unknown. 一个是“中立”,一个是“最大”,第三个是未知的。 What I need is to return a single value, between 0 and 1, that illustrates the amount that the unknown set is between the other two. 我需要返回一个介于0和1之间的值,该值说明了未知集在另两个之间的数量。

For example, in the image: 例如,在图像中:

点数

I would somehow get the 'distance' or 'weight' between Set A and Set B, then find out where Set C sits between them. 我会以某种方式获得Set A和Set B之间的“距离”或“权重”,然后找出Set C位于它们之间的位置。 In this example, i would expect a value of around 75%, or 0.75. 在此示例中,我希望该值约为75%或0.75。

I have looked at using point set registration algorithms that return a scale amount to match Set C to Set B, but i am not convinced that this is the best way. 我已经研究过使用点集注册算法,该算法会返回比例值以将Set C匹配到Set B,但是我不认为这是最好的方法。 What approach would be suitable for this problem? 哪种方法适合该问题? What algorithms should I be searching for? 我应该搜索什么算法?

You could try to solve this with a simple linear interpolation between the two sets. 您可以尝试通过两组之间的简单线性插值来解决此问题。 This works if the transition between the sets is indeed nearly linear. 如果集合之间的过渡确实几乎是线性的,则此方法有效。 If you know that it is something else, you can adapt the interpolation function. 如果您知道其他情况,则可以调整插值功能。

Let us focus on a single point p . 让我们专注于单个点p We know its coordinates in all sets p_A , p_B , and p_C . 我们知道在所有集合p_Ap_Bp_C Then, we specify that p_C is more or less a linear interpolation between p_A and p_B with parameter t (where t=0 represents set A and t=1 represents set B): 然后,我们指定p_C是带有参数t p_Ap_B之间的线性插值(其中t=0代表集合A, t=1代表集合B):

      p_C = (1 - t) * p_A + t * p_B
          = p_A - t * p_A + t * p_B
          = p_A + t * (p_B - p_A)
p_C - p_A = t * (p_B - p_A)

The question now is to find a t that approximately holds for all your points. 现在的问题是找到一个对所有点都近似成立的t

We can solve this by stating the problem as a linear least squares problem. 我们可以通过将问题表示为线性最小二乘问题来解决此问题。 Ie we want to minimize the summed residuals (difference between left-hand sides and right-hand sides of the above equation) for all points: 也就是说,我们要最小化所有点的总和残差(上述等式的左侧和右侧之间的差):

arg min_t Σ_i (pi_C.x - pi_A.x - t * (pi_B.x - pi_A.x))^2
               + (pi_C.y - pi_A.y - t * (pi_B.y - pi_A.y))^2

The optimal t is then: 最优t为:

numX = Σ_i (pi_A.x^2 - pi_A.x * pi_B.x - pi_A.x * pi_C.x + pi_B.x * pi_C.x)
numY = Σ_i (pi_A.y^2 - pi_A.y * pi_B.y - pi_A.y * pi_C.y + pi_B.y * pi_C.y)
denX = Σ_i (pi_A.x^2 - 2 * pi_A.x * pi_B.x + pi_B.x^2)
denY = Σ_i (pi_A.y^2 - 2 * pi_A.y * pi_B.y + pi_B.y^2)
t = (numX + numY) / (denX + denY)

If your points have higher dimension, just add the new dimension with the same pattern. 如果您的点具有更高的尺寸,只需添加具有相同图案的新尺寸即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM