Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Orientation from two (or three) positions (points)

Discussion in 'Scripting' started by wxxhrt, Jan 9, 2023.

  1. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    TLDR:-

    Hi I'm not so great at maths.

    If I have a cuboid in the physical world(the size of which I know) and I know the world positions of any two fixed points on the surface of that cuboid, is it possible to work out the orientation of that cuboid? If not does this become possible knowing the world positions of three fixed points rather than two.

    Longer:-

    I'm experimenting with sending position data to Unity from physical UWB tags in the real world. These tags are sending position data into Unity so that is one job done.

    Next I'd like to work out the orientation of cardboard boxes in the real world, I can place up to 3 tags on a cardboard box and get each tags position, id like the cardboard box to be able to be moved and rotated and this be reflected in Unity, however all I have is the position data of up to 3 tags attached to the cardboard box.

    I'd thought if I placed two tags on opposite corners of the box and then I could easily work out its centre. Would this be enough to know which direction it is rotated in?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Three non-collinear points are necessary to determine planar orientation.

    That is NOT the complete orientation!

    To understand what I mean, hold up 3 fingers in a triangle and place a playing card on those 3 fingers.

    Don't move those 3 fingers, but note how you can rotate the card around to any heading.

    However, if the card is touching all 3 fingers then it will always be in the same plane.
     
    wxxhrt and Bunny83 like this.
  3. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi @Kurt-Dekker

    This is a shame! But I think I understand. However does this change if rather than a flat playing card the object is a 3d cuboid with known distances between each point?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    If you predefine three points on the cuboid, say the top, the bottom left and the bottom right, then it would define the orientation if you knew the positions of those points.

    Rather than you and I going back and forth ceaselessly with "What if I xxx?" questions, why don't you try it out yourself with some orientation testing. If you have no idea how to start, here's a functioning example of using three points to orient a tank, which is already oriented to a given compass heading:

    Full source linked in description below video.

     
    wxxhrt likes this.
  5. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Thanks so much!