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

  • 2
    \$\begingroup\$ These corner points are expressed in 3D space, or are they 2D points in screen space (or calculated with respect to a camera view)? Are the corners known exactly, or is there some error/jitter we need to smooth out? \$\endgroup\$
    – DMGregory
    Commented Feb 7 at 11:18
  • \$\begingroup\$ This: gamedev.stackexchange.com/a/138035/10408 ? \$\endgroup\$
    – Theraot
    Commented Feb 7 at 11:33
  • \$\begingroup\$ this is some insanely advanced algebra, I tried writing an answer but I've given up as it was taking hours. you can detect the movement but you need to understand a ton of advanced functions. Theres surely a better way. Why do you need to do this, it seems utterly useless? \$\endgroup\$
    – Pow
    Commented Feb 8 at 13:21
  • \$\begingroup\$ @DMGregory These three points are coming from realsense using stereoCamera and it is accurate as I have checked it by myself. it is in x y and z. these points are coming based on stereoScopic camera \$\endgroup\$ Commented Feb 12 at 5:29
  • \$\begingroup\$ @Pow Exactly, Well, I found a way to actually do it. I chose to take those coordinates and pass it to Unity Script using Socket and then calculate there. p.s. this is more easier way to do it. as Python is not pretty complicated for 3d stuff in my opinion. \$\endgroup\$ Commented Feb 12 at 5:33

1 Answer 1


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)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .