【问题标题】:Highest point along Up Vector沿向上向量的最高点
【发布时间】:2021-05-01 11:29:03
【问题描述】:

我们有正常的 3 轴坐标系。然后我们有一个向量,比如“向上向量”,它可以向任何方向倾斜,我们有几个点,比如 P1、P2、P3、P4。

Check this pic for info

现在,正常情况下,如果我们想检查其中哪个点最高,我们只需检查它的 Y 坐标(假设它是垂直轴)。

但我想:

沿“向上向量”查找最高点。 之后,沿“Up Vector”将其他剩余点平移适量,使所有点与最高点处于同一水平。

请记住,我们想要沿 Up 向量的最高点

如何做到这一点?

【问题讨论】:

  • 来吧,没人知道吗?

标签: vector quaternions coordinate-systems


【解决方案1】:

下面的代码就是这样做的:

from mpl_toolkits import mplot3d

import numpy as np
from pyquaternion import Quaternion

import matplotlib.pyplot as plt


fig = plt.figure()
ax = plt.axes(projection="3d")

# draw vector

world_up = [0, 0, 0, 0, 0, 1]
local_up = [0, 0, 0, 1, 1, 1]

ax.quiver(*world_up, color='r')
ax.quiver(*local_up, color='b')


def normalize(vec):
    normalized_v = vec / np.linalg.norm(vec)
    return normalized_v


vector1 = normalize(np.array(world_up[3:]))
vector2 = normalize(np.array(local_up[3:]))

points = [np.array([0.1, 0.4, 0.5]) + vector2*0.2,
          np.array([0.2, 0.5, 0.3]),
          np.array([0.5, 0.2, 0.3]),
          np.array([0.4, 0.1, 0.5]) - vector2*0.2]

for index, point in enumerate(points):
    ax.scatter(*point)

dot_product = vector1.dot(vector2)
theta_rad = np.arccos(dot_product)
theta_deg = np.rad2deg(theta_rad)

vector3 = normalize(np.cross(vector1, vector2))

rotator = Quaternion(axis=vector3, angle=-theta_rad)

highest = 0
highest_index = 0
for index, point in enumerate(points):
    new_point = rotator.rotate(point)
    if new_point[2] > highest:
        highest = new_point[2]
        highest_index = index
    ax.scatter(*new_point, c='gray')

ax.text(*rotator.rotate(points[highest_index]), "Highest", 'z', c='red')
ax.text(*points[highest_index], "Highest", 'z', c='red')

ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.set_zlim([-1.5, 1.5])
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.set_title("Vectors")

plt.show()

Check results here

任何人都可以提出改进或替代方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多