#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Location
    Houston
    Posts
    48
    Rep Power
    11

    Question Trapezoid 2d Affine Transform


    Hi,
    I'm trying to get an affine transform that will turn a square image into a trapezoid like this:
    original
    Code:
    +----+
    |    |
    |    |
    +----+
    transformed
    Code:
       +--+
      /    \
     /      \
    +--------+
    I understand that the transform matrix has a row for each axis and that each axis has a scale and a skew, but that's about it. Sometimes the numbers get together behind the scenes and hold a seance where they do inexplicable things like boil frogs and rotate entire images. So if there's a good resource on that, I'd like to know about it.

    Thanks for any help
    Neal
  2. #2
  3. C# Addict.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Earth
    Posts
    283
    Rep Power
    28
    Here is the matrix for 2D transformations:

    1 2 3
    4 5 6
    7 8 9

    You will want to mess with values 7 and 8.
    They are usually 0.

    EDIT:
    I agree matrixes are magical in nature at first, but after you use them long enough then they loose their magic and gain ingenuity.
    Last edited by BioSlayer; February 27th, 2007 at 11:06 PM.
    There are none so blind as those who will not see. Jonathan Swift

    My 2D Physics Engine.
    My Remake of UQM.
    Both are written in C#.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Location
    Houston
    Posts
    48
    Rep Power
    11
    Do you know how to do it in Java? It looks to me like they don't want you playing with the bottom row.

    Here's the javadoc for AffineTransform
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    You might be confused here: an affine transformation can never map a square to a trapezoid, only to a parallelogram. What you really want is a projective transformation.

    Some background.
  8. #5
  9. C# Addict.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Earth
    Posts
    283
    Rep Power
    28
    Originally Posted by Nialsh
    Do you know how to do it in Java? It looks to me like they don't want you playing with the bottom row.

    Here's the javadoc for AffineTransform
    Since that bottom row is implied (not really there) you can't do what you want.
    There are none so blind as those who will not see. Jonathan Swift

    My 2D Physics Engine.
    My Remake of UQM.
    Both are written in C#.

IMN logo majestic logo threadwatch logo seochat tools logo