简体   繁体   English

给定 R^p 中的 2 个多维点,如何在通过这两个点的线上投影 N 个个体?

[英]Given 2 multidimensionals points in R^p, how to project N individuals on the line passing through those two points?

I have 2 points in R^p, and i want to project N individuals on the line passing through those two points.我在 R^p 中有 2 个点,我想在通过这两个点的线上投影 N 个个体。 To be exact, i want the coordinates of every N individuals on the 1D space created by this line.确切地说,我想要由这条线创建的一维空间上每 N 个个体的坐标。

The operations will be repeated multiple times on different points, so an automatic method is needed.操作将在不同的点上重复多次,因此需要一种自动方法。 I was wondering if it exists a package to find the equation of the line.我想知道它是否存在一个包来找到这条线的方程。 The projection should be easy to implement.该投影应该易于实施。

Edit (Vishwas comment) :编辑(Vishwas 评论):

Given two points y1 = (1,4) & y2 = (5,6) do a projection ( https://en.wikipedia.org/wiki/Projection_(mathematics) ) of {x1,...,xN} in R2 onto the line passing through y1 and y2.给定两个点Y1 =(1,4)Y2 =(5,6)做投影( https://en.wikipedia.org/wiki/Projection_(mathematics)的){X1,...,XN}中R2 到通过 y1 和 y2 的线上。

Expected output: the coordinates of each projected points {x1,...,xN} in the original space.预期输出:原始空间中每个投影点 {x1,...,xN} 的坐标。

Your projection of point xi is zi = y1 + ti × (y2 - y1) for some suitable ti.对于某些合适的 ti,点 xi 的投影是 zi = y1 + ti × (y2 - y1)。 The remaining difference xi - zi is orthogonal to the line, so the dot product (xi - zi) • (y2 - y1) = 0. Put in the definition of zi and you get an equation that is linear in ti.剩下的差 xi - zi 与直线正交,所以点积 (xi - zi) • (y2 - y1) = 0。输入 zi 的定义,你会得到一个在 ti 中线性的方程。 You can solve it for ti, then use that to compute zi.您可以为 ti 求解,然后使用它来计算 zi。

If you want to do this operation for many points, you could come up with a precomputation that expresses this whole operation eg as a matrix multiplication.如果你想对许多点进行这个操作,你可以想出一个预计算来表达整个操作,例如矩阵乘法。 As the line you project to dues not necessarily pass through the origin, you need an assume transformation, which can be expressed as an (p+1) × (p+1) matrix acting on homogeneous coordinates.由于您投影到会费的线不一定通过原点,因此您需要一个假设变换,它可以表示为作用于齐次坐标的 (p+1) × (p+1) 矩阵。

Let's switch nomenclature to single letter symbols.让我们将命名法切换为单字母符号。 Let your line be defined by points a and b.让您的线由点 a 和 b 定义。 We project point x to z = a + t (b - a).我们将点 x 投影到 z = a + t (b - a)。 So you get 0 = (x - a - t (b - a)) • (b - a) = (x - a) • (b - a) - t (b - a) • (b - a) which you can solve for t = ((x - a) • (b - a)) / ((b - a) • (b - a)).所以你得到 0 = (x - a - t (b - a)) • (b - a) = (x - a) • (b - a) - t (b - a) • (b - a)可以求解 t = ((x - a) • (b - a)) / ((b - a) • (b - a))。

Here is a bit of Python code which you can use to compare against your implementation:这是一些 Python 代码,您可以使用它们与您的实现进行比较:

def project(p, a, b, xs):
  ab = [b[i] - a[i] for i in range(p)]
  abab = sum(i*i for i in ab)
  zs = []
  for x in xs:
    t = sum((x[i] - a[i])*ab[i] for i in range(p)) / abab
    z = [a[i] + t*ab[i] for i in range(p)]
    zs.append(z)
  return zs

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

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