简体   繁体   中英

Get 2D direction that represents tilt direction of 3D object

I have a 3D object in space. Here it is from a top-down perspective: 在此处输入图片说明

Y is towards us, so we can't see that axis. It's not tilting at all, so it's direction would be Vector2(0,0).

在此处输入图片说明

Now the object is tilting forward. It's tilting towards the positive X axis. The direction would now be Vector2(0,1)

在此处输入图片说明

Now it's tilting to the left, it's direction would be Vector(-1,0)

在此处输入图片说明

Now, finally, it's tilting forward and the left, it's direction would be around Vector(-0.7071, 0.7071)

I'm using Unity, so I have access to the object's Quaternion and Euler Angles as a 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.

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).

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. 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.

I hope I didn't messed up something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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