Thread: 2d rotations

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    4

    2d rotations

    Hi there

    As you can see I'm new into this field, and I don't know how to solve the following simple problem.
    Attachment 8405
    Let's say I wish to move an object from point A in point B. I know the x, y coordinates of A and B. How can I detect the rotation angle between A and B, using a matrix.
    All I can do is to solve this problem is using Pythagoras theorem, but I need to understand how to do it using matrices.

    thank you

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Method 1: Write everything in polar and subtract angles.
    Method 2: Use trigonometry to find the angle from x (or y) axis to A, and x (or y) axis to B, and subtract. (This is really the same as method 1.)

    I don't know what you could mean by "as a matrix" since you are going from 4 values (x and y coordinates) to 1 value (the angle theta).

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, like tabstop says. You can, however "move" the object using a matrix by putting the sin/cos values in a matrix and multiplying the current coordinates by the new values. #

    Check out "Transformation Matrix":
    http://en.wikipedia.org/wiki/Transformation_matrix

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Well, that depends on what you want. If you want the angle between A and B simple trig is the best solution. If you have A and the angle and want to fidn B then use a rotation matrix.

    | 1 0 0 0 |
    | 0 1 0 0 |
    | 0 0 1 0 |
    | x y z 1 |

    is your initial point A

    | cos sin 0 0 |
    | -sin cos 0 0 |
    | 0 0 1 0 |
    | 0 0 0 1 |

    is your rotation matrix for theta

    then you simply multiply them and the product gives you a new 4x4 matrix for the point B. This is assuming you want to use computer hardware. If you want the fastest method on paper, then use the 1x4 point matrix instead, which i believe is

    | X |
    | Y |
    | Z |
    | 1 |

    then multiply it by the 4x4 rotationmatrix above, which results in a new 1x4 point matrix

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That's for 3d. For 2d, you basically drop one dimension. The point is
    | 1 0 0 |
    | 0 1 0 |
    | x y 1 |

    The rotation matrix is
    | cos sin 0 |
    | -sin cos 0 |
    | 0 0 1 |
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    yeah I gave the 3d for the simple fact its supported directly in hardware, 2d is not. 3d is also supprted directly by DirectX

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    4
    Many thx for you valuable replays. Now I'm taking the pencil to begin to learn about transformation matrix.

    I'll tell you which is my real problem. I'm in the last year in computer science and i have to detect head rotation angles. It's about detecting yaw, pitch, roll angles. All I know is that I can use Euleur angles or quaternions.
    Attachment 8406
    The project is in C++. The user has to chose the a, b, c dots for mouth, left eye and right eye respectively and my application to return the yaw, pitch, roll angles.

    Until now I can get the a,b, c coordinates in 2D as mouse events.
    Which is the next step? Many thanks.

    Are any libs which I can use in order to obtain those angles, when I have x, y coordinates for each point?

    ps: sorry for my bad English, It's not my native language. If I sad something bad, pls tell me and I'll rephrase.
    Last edited by beginner.alx; 09-16-2008 at 12:22 PM.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    atan2f() will give you the angle.

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    We worked on a similar problem awhile ago. The problem si that the segments AB BC abd CA are not of uniform size for any two people, plus you have to determien the distance. Since the proportions change with distance and with person, it is fairly difficult to get a perfectly accurate answer on yaw pitch and roll for their gaze. The best we coudl do using neural networks was to get a fairly close approximation, it was still off by as much as 15-20 degrees though. For a single person or sample population you can get much mroe accurate, btu theres no guarantee that accuracy will hold for untested examples.

  10. #10
    Registered User
    Join Date
    Sep 2008
    Posts
    4
    I need the head angles. A transformation from 2D in 3D.

  11. #11
    Registered User
    Join Date
    Sep 2008
    Posts
    4

    Lightbulb

    I think I've find something: Estimation of Head Orientation Using Characteristic Points of
    Face
    see chapter 5.2 on page 44.
    Allot of math is involved here . I'm afraid.

  12. #12
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You need to take into account the height of the camera b/c even though their heads might be level they appear to be angled due to perspective projection and camera height. You also have no depth information for this image.

    If you can determine the look vector of the heads then the rest should be fairly straightforward since you know the correct right, up and look vectors. Once you determine the precise look vector and right vector then you can cross them to get the up vector. Then you can take the dot product of those vectors with the 'level' or reference vectors to determine the angles on x, y and z.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D in directX
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 01-25-2009, 11:23 AM
  2. Replies: 16
    Last Post: 09-22-2006, 03:39 PM
  3. Replies: 0
    Last Post: 01-20-2006, 11:11 AM
  4. 2D Game Programming Tutorials?
    By Zeusbwr in forum Game Programming
    Replies: 9
    Last Post: 11-04-2004, 08:36 AM
  5. returning 2D arrays
    By ... in forum C++ Programming
    Replies: 2
    Last Post: 09-02-2003, 12:28 PM