获取三维矢量并生成角分布p

2024-07-05 14:28:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一堆向量,它们表示三维空间中的对象,相对于0轴上表示的平面来说是灵活的。我可以很高兴地绘制这些向量,如下所示:

Vectors plotted in quiver3d plot with matplotlib

这些都是以单位向量绘制的。你知道吗

我想把这些向量画成一个二维圆的角分布,在这个圆上画一个点,代表垂直方向的角度(在这个例子中,我知道这是(0,0,1))和360度角。你知道吗

知道从垂直方向的角度很容易,我已经有了一个函数来做到这一点:

import numpy as np
import math

def CalculateAngleBetweenVector(vector, vector2):
    """
    This function was mainly created to double check the angle between the input and outputs of the applyrotationmatrix function
    """
    dp = np.dot(vector, vector2)

    maga = math.sqrt((vector[0] ** 2) + vector[1] ** 2 + vector[2] ** 2)
    magb = math.sqrt((vector2[0] ** 2) + vector2[1] ** 2 + vector2[2] ** 2)
    magc = maga * magb

    dpmag = dp / magc

    angleindeg = ((math.acos(dpmag)) * 180) / math.pi

    return angleindeg

现在的问题是,我不知道如何计算圆的角度。最好的办法是什么?你知道吗

我有一个想法,把所有的向量投影到二维空间,然后从0,1,0或1,0,0轴计算角度,但是我只得到0-180,而不是-180到+180。还有别的办法吗?你知道吗


Tags: theimportnp绘制functionmathsqrt方向