I got four corner points of the object which are topLeft, topRight, BottomRight, BottomLeft and are as clockwise. I want a rotation values in X, Y and Z for unity object to rotate based on the rotation of these four points. Actually, these points are coming from python and I want to represent rotation of it on unity object which has Rotation x,y and z
1 Answers
If the object is a square, you can do this:
// Find perpendicular vectors running sideways...
Vector3 right = TopRight + BottomRight - TopLeft - BottomLeft;
//...and vertically along the object's edges.
Vector3 up = TopLeft + TopRight - BottomLeft - BottomRight;
// Use a little vector math to get the remaining
// perpendicular axis, forming a basis.
Vector3 forward = Vector3.Cross(right, up);
// Extract the orientation of that coordinate basis.
Quaternion rotation = Quaternion.LookRotation(forward, up);
Then you can use the quaternion directly (good if you need to interpolate/blend the rotation) or extract rotation.eulerAngles
if you need the output as angles (just note these are not as nicely behaved and can have unintuitive and large value discontinuities for small orientation differences, even though they still express the same orientation as the source quaternion)

- 134,153
- 22
- 242
- 357
p.s. this is more easier way to do it. as Python is not pretty complicated for 3d stuff in my opinion.
– Yagnik Joshi Feb 12 '24 at 05:33