如何根据参考点平移移动点的位置



给定两个移动点/粒子,它们的位置在笛卡尔坐标x、y、z中作为时间的函数,如下所示,如何使其中一个点居中并计算第二个点的最终位置,同时保持它们的相对距离和方向不变?

# Given the absolute positions of point 1 (p1) and point 2 (p2): 
p1 = [
[7.74, 9.48, 9.61],
[7.02, 8.83, 9.42],
[7.91, 9.08, 9.56],
[8.61, 8.92, 9.50],
[8.87, 9.35, 9.63],
[7.77, 9.83, 9.86]
]
p2 = [
[7.90, 10.48, 10.2],
[8.30, 10.74, 9.59],
[8.23, 10.24, 9.86],
[8.15, 10.42, 9.91],
[8.05, 10.44, 9.92],
[8.4, 10.78, 10.04]
]
# Center p1. It does not necessarily have to be at (0, 0, 0). 
p1 = [
[0, 0, 0], 
[0, 0, 0], 
[0, 0, 0],
[0, 0, 0],
[0, 0, 0], 
[0, 0, 0]
]
# Translate p2 so its relative position (distance & orientation) relative to p1 remains constant. 
p2 = []

直觉上,我会尝试找到转换的平移和旋转矩阵。我看了scipy.spatial,但找不到解决问题的方法(至少我能理解(。

我该如何解决这个问题?

编辑1:两个点的移动应该是相互独立的,所以它们的距离+方向不应该是恒定的。我的目标是检验这个假设:这些点是否会对彼此产生任何影响
具体来说,我想计算点2相对于点1的密度,但为了使计算有意义,我需要首先固定点1。希望这能进一步澄清问题。

如果你不熟悉线性代数,这可能有点神秘,但本质上你可以操纵向量来计算两点之间向量的长度和圆柱旋转。它会是这样的:

import numpy as np
from scipy import linalg
p1 = [
[7.74, 9.48, 9.61],
[7.02, 8.83, 9.42],
[7.91, 9.08, 9.56],
[8.61, 8.92, 9.50],
[8.87, 9.35, 9.63],
[7.77, 9.83, 9.86]
]
p2 = [
[7.90, 10.48, 10.2],
[8.30, 10.74, 9.59],
[8.23, 10.24, 9.86],
[8.15, 10.42, 9.91],
[8.05, 10.44, 9.92],
[8.4, 10.78, 10.04]
]
# Transform lists to arrays
a1, a2 = np.array(p1), np.array(p2)
# Get vector from p1 to p2
v = a2 - a1
# Get the norm of all vectors p1p2, i.e. the distance between p1 and p2
n = linalg.norm(v, axis=1)
# Normalize the vectors if need be
unit_v = v / n[:, None]
# Normalize the vectors in xy plane
unit_v_xy = (v / linalg.norm(v[:, 0:2], axis=1)[:, None])[:, 0:2]
# Get angles modulo pi in xy plane
xy_angles = np.column_stack((np.arccos(unit_v_xy[:, 0]), np.arcsin(unit_v_xy[:, 1])))
# Get pitch angle, i.e. angle between vector and z axis
pitch_angles = np.arccos(np.dot(unit_v, np.array([0, 0, 1])))

最新更新