0

给定两个在笛卡尔坐标 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。希望这能进一步澄清问题。

4

1 回答 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])))
于 2020-04-06T16:39:35.057 回答