简体   繁体   English

获取表示3D对象倾斜方向的2D方向

[英]Get 2D direction that represents tilt direction of 3D object

I have a 3D object in space. 我在太空中有一个3D对象。 Here it is from a top-down perspective: 这里是从上到下的角度: 在此处输入图片说明

Y is towards us, so we can't see that axis. Y朝向我们,所以我们看不到该轴。 It's not tilting at all, so it's direction would be Vector2(0,0). 它根本不倾斜,因此方向是Vector2(0,0)。

在此处输入图片说明

Now the object is tilting forward. 现在物体正在向前倾斜。 It's tilting towards the positive X axis. 它正向正X轴倾斜。 The direction would now be Vector2(0,1) 现在方向将为Vector2(0,1)

在此处输入图片说明

Now it's tilting to the left, it's direction would be Vector(-1,0) 现在它向左倾斜,方向是Vector(-1,0)

在此处输入图片说明

Now, finally, it's tilting forward and the left, it's direction would be around Vector(-0.7071, 0.7071) 现在,最后,它向前和向左倾斜,方向将围绕Vector(-0.7071,0.7071)

I'm using Unity, so I have access to the object's Quaternion and Euler Angles as a Vector3. 我正在使用Unity,因此可以将对象的四元数和欧拉角作为Vector3进行访问。 How would I calculate the object's tilt direction from the object's rotation? 如何根据对象的旋转来计算对象的倾斜方向?

As far as I understand your idea, you are looking for orthogonally casted parameters of normal vector (abstractly attached to the body). 据我了解您的想法,您正在寻找正交向量的法线向量(抽象地附着在人体上)。 If it turns forward this vector after cast gets values (0,1) like you've said. 如果它向前旋转,则该向量在像您所说的那样获得值(0,1)之后。

You can receive x and y components of that vector by decomposition - as a sum of two perpendicular vectors, each one represents one component (x,0) and (0,y). 您可以通过分解接收该向量的x和y分量-作为两个垂直向量的总和,每个向量代表一个分量(x,0)和(0,y)。

Another way of achieving that result would be to have a point in 3D space P(0,0,1) which represents top of such vector. 获得该结果的另一种方法是在3D空间P(0,0,1)中具有一个点,该点表示此类矢量的顶部。 Now simply applying rotation matrix this point would be moved toward new position which is P(x,y,z) and here you can get x and y you are looking for. 现在只需简单地应用旋转矩阵,该点便会移至新位置P(x,y,z),在这里您可以获得所需的x和y。

I hope I didn't messed up something. 我希望我不会弄乱什么。

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

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