From AffineTransform to PerspectiveTransform

Discussion in 'Java' started by Andrew Thompson, Oct 23, 2008.

  1. I have been trying, unsuccessfully over the last few days,
    to create a custom AffineTransfrom that creates the effect
    of seeing a flat surface at an angle, a 'perspective view'.

    My efforts so far have been abysmal. I tried extending
    AffineTransform
    and overriding the transform(Point2D,Point2D) method, but is was
    not getting called.. I went on to override every single transform()
    method I could find, but *none* of them are getting called.

    Questions.
    1) Is it possible to create a perspective view of an object using
    just (the inbuilt transforms) shear, scale, translate..?
    (I'm thinking 'no'.)
    2) Is an AffineTransform the way to go with this, or am I missing
    how they are supposed to be used?
    3) Does anybody have an insight into why my overridden methods
    were not getting called? (Yes, yes. I know a code example could
    help here, but I am hoping there is something I missed that another
    person has solved previously.)

    --
    Andrew T.
    pscode.org
    Andrew Thompson, Oct 23, 2008
    #1
    1. Advertising

  2. Peter Duniho wrote:
    > On Wed, 22 Oct 2008 19:49:52 -0700, Andrew Thompson
    > <> wrote:
    >
    >> I have been trying, unsuccessfully over the last few days,
    >> to create a custom AffineTransfrom that creates the effect
    >> of seeing a flat surface at an angle, a 'perspective view'.
    >>
    >> My efforts so far have been abysmal. I tried extending
    >> AffineTransform
    >> and overriding the transform(Point2D,Point2D) method, but is was
    >> not getting called.. I went on to override every single transform()
    >> method I could find, but *none* of them are getting called.
    >>
    >> Questions.
    >> 1) Is it possible to create a perspective view of an object using
    >> just (the inbuilt transforms) shear, scale, translate..?
    >> (I'm thinking 'no'.)

    >
    > I'm thinking no. My geometry is a little rusty these days, but my
    > recollection is that an affine transformation by definition can't do
    > this.


    Well, actually ...

    sort-a.

    http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection

    I don't think this can be done with java.awt.geom.AffineTransform, though.
    Harold Yarmouth, Oct 23, 2008
    #2
    1. Advertising

  3. In article <gdpv7f$h9p$>,
    Harold Yarmouth <> wrote:

    > Peter Duniho wrote:
    > > On Wed, 22 Oct 2008 19:49:52 -0700, Andrew Thompson
    > > <> wrote:
    > >
    > >> I have been trying, unsuccessfully over the last few days,
    > >> to create a custom AffineTransfrom that creates the effect
    > >> of seeing a flat surface at an angle, a 'perspective view'.
    > >>
    > >> My efforts so far have been abysmal. I tried extending
    > >> AffineTransform
    > >> and overriding the transform(Point2D,Point2D) method, but is was
    > >> not getting called.. I went on to override every single transform()
    > >> method I could find, but *none* of them are getting called.
    > >>
    > >> Questions.
    > >> 1) Is it possible to create a perspective view of an object using
    > >> just (the inbuilt transforms) shear, scale, translate..?
    > >> (I'm thinking 'no'.)

    > >
    > > I'm thinking no. My geometry is a little rusty these days, but my
    > > recollection is that an affine transformation by definition can't do
    > > this.

    >
    > Well, actually ...
    >
    > sort-a.
    >
    > http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection
    >
    > I don't think this can be done with java.awt.geom.AffineTransform, though.


    You might look at PerspectiveTransform:

    <http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja
    vax/media/jai/PerspectiveTransform.html>

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
    John B. Matthews, Oct 23, 2008
    #3
  4. Peter Duniho wrote:
    > On Thu, 23 Oct 2008 06:45:59 -0700, Harold Yarmouth
    > <> wrote:
    >
    >>> I'm thinking no. My geometry is a little rusty these days, but my
    >>> recollection is that an affine transformation by definition can't do
    >>> this.

    >>
    >> Well, actually ...
    >>
    >> sort-a.
    >>
    >> http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection
    >>
    >> I don't think this can be done with java.awt.geom.AffineTransform,
    >> though.

    >
    > Then why did you say "sort-a"? My statement was specifically about
    > affine transformations, not transforms in general.
    >
    > In what way does the perspective projection matrix relate to my
    > statement about affine transformations?


    Because the perspective projection trick discussed there uses an affine
    transform in a higher-dimensional space "under the hood".
    Harold Yarmouth, Oct 24, 2008
    #4
  5. Peter Duniho wrote:
    > On Thu, 23 Oct 2008 20:03:55 -0700, Harold Yarmouth
    > <> wrote:
    >
    >>> In what way does the perspective projection matrix relate to my
    >>> statement about affine transformations?

    >>
    >> Because the perspective projection trick discussed there uses an
    >> affine transform in a higher-dimensional space "under the hood".

    >
    > Where? Please be more specific.
    >
    > It's true that a matrix transformation is used. But by definition, it's
    > not an affine transform.
    >
    > Are you perhaps being misled


    Is there a reason for your less-than-civil attitude here?

    Matrix transformations are, by definition, affine transforms in the
    space of the same dimensionality as the matrix. In fact they're the
    subset of linear transforms, affine transforms that don't include any
    translation component.

    Indeed, there is a one-to-one correspondence between linear operators on
    an n-dimensional vector space and nxn matrices, given a particular
    ordered basis for the vector space.

    The transformation in the lower-dimensional space that is produced is
    not affine, but it is produced by doing a linear transformation in a
    higher-dimensional space and then projecting down in a specific (and
    non-affine) way.

    The linear transformation in the higher-dimensional space can help
    effect a translation as well as a perspective transform in the lower.
    Indeed, it can induce any
    affine-transformation-followed-by-perspective-transformation from what
    I've seen.

    Now, if you're done pointlessly nit-picking other peoples' attempts to
    be helpful ...
    Harold Yarmouth, Oct 24, 2008
    #5
  6. On Oct 24, 12:59 am, "John B. Matthews" <> wrote:

    > You might look at PerspectiveTransform:
    >
    > <http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja
    > vax/media/jai/PerspectiveTransform.html>


    That seems to do what I need. Even better is that it
    also offers the inverse transform - which is what I
    ultimately want - the ability to grab an image of a
    perspective view of some 'flat' document or painting
    and *remove* the warping from the perspective view.

    I've finally found a good reason to delve into JAI
    (yeah sure, the vastly increased range of formats
    that JAI offers would be funky, but that was never
    vital to my projects).

    Thanks also to the other contributors. I am reading
    the ongoing discussion with interest, since I do not
    have a great deal of experience with / knowledge of
    transforms (though I'm OK at geometry, which is why I
    thought I'd try writing one, failing finding an existing
    class to do it for me).

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, Oct 24, 2008
    #6
  7. In article
    <>,
    Andrew Thompson <> wrote:

    > On Oct 24, 12:59 am, "John B. Matthews" <> wrote:

    [...]
    > Thanks also to the other contributors.


    Thanks, too.

    > I am reading the ongoing discussion with interest, since I do not
    > have a great deal of experience with / knowledge of transforms
    > (though I'm OK at geometry, which is why I thought I'd try writing
    > one, failing finding an existing class to do it for me).


    I've used the results, as found in Java, GL and Quartz, but I'm weak
    on the algebra. I see the correspondence between an affine transform
    using homogeneous coordinates and the Java class AffineTransform:

    <http://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformati
    ons>
    <http://java.sun.com/javase/6/docs/api/java/awt/geom/AffineTransform.ht
    ml>

    Now I compare the perspective transform with the corresponding Java
    implementation, but I'm having trouble reconciling the 4D matrix in
    the former with the 3D matrix in the latter:

    <http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_project
    ion>
    <http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/
    javax/media/jai/PerspectiveTransform.html>

    I'd be grateful is anyone can elaborate.

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
    John B. Matthews, Oct 24, 2008
    #7
  8. Peter Duniho wrote:
    > On Thu, 23 Oct 2008 20:23:10 -0700, Harold Yarmouth
    > <> wrote:
    >
    >> Is there a reason for your less-than-civil attitude here?

    >
    > Any perception of "less-than-civil" is strictly in your own head.


    I disagree. You have been brusque and slightly rude. Particularly with
    this last, personal comment about something being all in my head.

    >> Matrix transformations are, by definition, affine transforms in the
    >> space of the same dimensionality as the matrix. In fact they're the
    >> subset of linear transforms, affine transforms that don't include any
    >> translation component.

    >
    > AffineTransform most certainly does "include any translation
    > component". If you want to argue that a true affine transform doesn't,
    > fine with me.


    I don't, and I don't like it when people try to put words in my mouth as
    an excuse to blast me in public. What is your problem with me, anyway?
    It's apparently personal. Yet I've never interacted with you before this
    thread, so how the hell can it be?

    I said, of course, that the subset of affine transforms called linear
    transforms are those that don't have translation components.

    You even quoted the paragraph where I said it.

    > As I said, my geometry and matrix math is a bit rusty


    Then perhaps you shouldn't jump to criticize that of other posters.
    Whatever your beefs with those posters.

    >> Indeed, there is a one-to-one correspondence between linear operators
    >> on an n-dimensional vector space and nxn matrices, given a particular
    >> ordered basis for the vector space.
    >>
    >> The transformation in the lower-dimensional space that is produced is
    >> not affine, but it is produced by doing a linear transformation in a
    >> higher-dimensional space and then projecting down in a specific (and
    >> non-affine) way.

    >
    > That's fine.


    And that's what I originally said that you originally took issue with.

    > But irrelevant to the AffineTransform in Java, which doesn't include
    > those higher dimensions.


    Which I pointed out myself in the first post that you attacked.

    I was also pointing out, though, that it is not entirely true that
    perspective transforms cannot be accomplished using affine transforms,
    the way somebody had indicated. I was pointing out that perspective
    transforms in a low dimensional space are quite often accomplished using
    affine (indeed, linear) transforms in a higher dimensional space. Though
    Java's AffineTransform class cannot be directly used to do this.

    Someone else posted to mention that JAI contains a PerspectiveTransform
    class in its API that does work that way under the hood.

    >> Now, if you're done pointlessly nit-picking other peoples' attempts to
    >> be helpful ...

    >
    > Um. You're a fine one to be speaking of nit-picking, yourself having
    > started the entire nit-picking part of this thread.


    I was pointing out something that I thought was interesting, and that
    clarified previous discussion.

    You were posting solely for the purpose of being rude to another person
    online, as near as I can tell, and far from clarifying anything you have
    muddied the waters, particularly with your latest post that actually
    attempts to stuff words in my mouth that are approximately opposite to
    what I'd actually said.

    The contrast could not be much more stark.

    (Oh, and a helpful hint for the future: when trying to stuff words in
    someone's mouth, quoting the text of what they actually said tends to
    undermine your effectiveness. :)
    Harold Yarmouth, Oct 25, 2008
    #8
  9. Lew wrote:
    > Peter Duniho wrote:
    >>> Are you perhaps being misled

    >
    > Harold Yarmouth wrote:
    >> Is there a reason for your less-than-civil attitude here?

    >
    > One would consider a dry, objective tone ...


    Are you reading the same posts that I am? His tone is quite clearly
    confrontational in the posts that I am referencing. "Are you being
    misled?", this or that "is strictly in your own head", something "most
    certainly does" something that I never claimed it didn't do, and so forth.

    At best, he is skimming my posts without reading them carefully, forming
    snap judgments, and then publicly claiming that I said or implied things
    other than what I actually did say.

    But his attitude reminds me of how people sound when they don't like
    someone, which makes me suspect that (for some reason I can't begin to
    fathom, given that our history of interaction is about three days old
    and consists of about three Usenet posts each) Peter has developed a
    personal beef with me and, unfortunately, is being influenced by this to
    act boorish towards me in public and not solely in private.
    Harold Yarmouth, Oct 25, 2008
    #9
  10. In article <>,
    "John B. Matthews" <> shamelessly follows up to
    his own post:

    > Now I compare the perspective transform with the corresponding Java
    > implementation, but I'm having trouble reconciling the 4D matrix in
    > the former with the 3D matrix in the latter:
    >

    <http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projectio
    n>
    <http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja
    vax/media/jai/PerspectiveTransform.html>
    >
    > I'd be grateful is anyone can elaborate.


    IIUC, the PerspectiveTransform uses homogeneous coordinates internally
    in a vector space having an additional dimension:

    <http://en.wikipedia.org/wiki/Homogeneous_coordinates#Use_in_computer_gra
    phics>

    [Instead of homogeneous, 'of the same kind,' the API uses the term
    homogenous, 'having a common descent.']

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
    John B. Matthews, Oct 25, 2008
    #10
  11. Andrew Thompson

    zerg Guest

    Harold Yarmouth wrote:
    > What is your problem with me, anyway? It's apparently personal.
    > Yet I've never interacted with you before this thread, so how the hell
    > can it be?


    Our "friend" Peter Duniho seems to behave the same way towards many
    people, so it probably isn't personal. Just an attitude problem on his part.

    Google Groups search for his posts in this newsgroup and you'll find
    that he's gotten into virtual fisticuffs with myself, some guy named
    Lew, some guy named Ben, and others, too, and that he's usually the one
    that threw the first punch.

    On the other hand, he posts a fair amount of non-hostile on-topic
    material too.

    All the same, it would be nice if he'd make the effort to refrain from
    posting as Mr. Hyde and only post as Dr. Jekyll.
    zerg, Oct 25, 2008
    #11
  12. Peter Duniho wrote:
    > On Fri, 24 Oct 2008 22:07:48 -0700, Harold Yarmouth
    > <> wrote:
    >>> AffineTransform most certainly does "include any translation
    >>> component". If you want to argue that a true affine transform
    >>> doesn't, fine with me.

    >>
    >> I don't, and I don't like it when people try to put words in my mouth
    >> as an excuse to blast me in public. What is your problem with me,
    >> anyway? It's apparently personal. Yet I've never interacted with you
    >> before this thread, so how the hell can it be?

    >
    > Hmmm...interesting. Yet another Aioe.net user who has some bizarre
    > sensitivity to perceived-but-nonexistent slights, who says things like
    > "put words in my mouth" when all I've done is reiterate what _you_
    > wrote, and who makes a point about saying "I've never interacted with
    > you before this thread".
    >
    > What next? Are you going to threaten legal action because I've
    > besmirched your good name?
    >
    > Sorry zerg/Twisted/Paul/Ben/Harold...I've had my fill. You'll have to
    > troll someone else this time.


    Anyone want to try and predict the next name he will be using ?

    Arne
    Arne Vajhøj, Oct 26, 2008
    #12
  13. zerg wrote:
    > Harold Yarmouth wrote:
    >> What is your problem with me, anyway? It's apparently personal.
    >> Yet I've never interacted with you before this thread, so how the hell
    >> can it be?

    >
    > Our "friend" Peter Duniho seems to behave the same way towards many
    > people, so it probably isn't personal. Just an attitude problem on his
    > part.


    Why are you talking to yourself ?

    Arne
    Arne Vajhøj, Oct 26, 2008
    #13
  14. Peter Duniho wrote:
    > On Fri, 24 Oct 2008 22:07:48 -0700, Harold Yarmouth
    > <> wrote:
    >
    >> [...]
    >>> AffineTransform most certainly does "include any translation
    >>> component". If you want to argue that a true affine transform
    >>> doesn't, fine with me.

    >>
    >> I don't, and I don't like it when people try to put words in my mouth
    >> as an excuse to blast me in public. What is your problem with me,
    >> anyway? It's apparently personal. Yet I've never interacted with you
    >> before this thread, so how the hell can it be?

    >
    > Hmmm...interesting. Yet another Aioe.net user who has some bizarre
    > sensitivity to perceived-but-nonexistent slights, who says things like
    > "put words in my mouth" when all I've done is reiterate what _you_
    > wrote, and who makes a point about saying "I've never interacted with
    > you before this thread".
    >
    > What next? Are you going to threaten legal action because I've
    > besmirched your good name?
    >
    > Sorry zerg/Twisted/Paul/Ben/Harold...I've had my fill. You'll have to
    > troll someone else this time.


    What have you been smoking, and where can I get some too?
    Harold Yarmouth, Oct 26, 2008
    #14
  15. Arne Vajhøj wrote:
    > Peter Duniho wrote:
    >> On Fri, 24 Oct 2008 22:07:48 -0700, Harold Yarmouth
    >> <> wrote:
    >>>> AffineTransform most certainly does "include any translation
    >>>> component". If you want to argue that a true affine transform
    >>>> doesn't, fine with me.
    >>>
    >>> I don't, and I don't like it when people try to put words in my mouth
    >>> as an excuse to blast me in public. What is your problem with me,
    >>> anyway? It's apparently personal. Yet I've never interacted with you
    >>> before this thread, so how the hell can it be?

    >>
    >> Hmmm...interesting. Yet another Aioe.net user who has some bizarre
    >> sensitivity to perceived-but-nonexistent slights, who says things like
    >> "put words in my mouth" when all I've done is reiterate what _you_
    >> wrote, and who makes a point about saying "I've never interacted with
    >> you before this thread".
    >>
    >> What next? Are you going to threaten legal action because I've
    >> besmirched your good name?
    >>
    >> Sorry zerg/Twisted/Paul/Ben/Harold...I've had my fill. You'll have to
    >> troll someone else this time.

    >
    > Anyone want to try and predict the next name he will be using ?


    I thought this was a newsgroup for discussing Java, not for making crazy
    theories about random people.
    Harold Yarmouth, Oct 26, 2008
    #15
  16. Lew wrote:
    > Harold Yarmouth wrote:
    >> Peter Duniho wrote:
    >>> On Thu, 23 Oct 2008 20:23:10 -0700, Harold Yarmouth
    >>> <> wrote:
    >>>
    >>>> Is there a reason for your less-than-civil attitude here?
    >>>
    >>> Any perception of "less-than-civil" is strictly in your own head.

    >>
    >> I disagree. You have been brusque and slightly rude. Particularly with
    >> this last, personal comment about something being all in my head.

    >
    > I am personally acquainted with when Peter gets "brusque" (good word,
    > BTW, even though it didn't apply


    It did apply.

    > Let it go and stop the flame war, all right?


    After you. You just insulted me yourself, and without cause.

    Why are you, Peter, and Arne suddenly posting a lot of completely
    off-topic posts and saying things about me that range from insulting to
    just plain strange? Why was Peter confrontational towards me without any
    apparent justification?

    I'm here to discuss Java, not get into fights or make pointless
    off-topic posts.

    It's a shame the same apparently cannot be said for everybody who posts
    here.
    Harold Yarmouth, Oct 26, 2008
    #16
  17. Lew wrote:
    > Lew wrote:
    >>> Let it go and stop the flame war, all right?

    >
    > Harold Yarmouth wrote:
    >> After you. You just insulted me yourself, and without cause.
    >>
    >> Why are you, Peter, and Arne suddenly posting a lot of completely
    >> off-topic posts and saying things about me that range from insulting
    >> to just plain strange? Why was Peter confrontational towards me
    >> without any apparent justification?

    >
    > Sigh.
    >
    > Plonk.


    You will need a large harddrive to keep a killfile with all his
    aliases !

    Arne
    Arne Vajhøj, Oct 26, 2008
    #17
  18. Andrew Thompson

    zerg Guest

    Arne Vajhøj wrote:
    > zerg wrote:
    >> Harold Yarmouth wrote:
    >>> What is your problem with me, anyway? It's apparently personal.
    >>> Yet I've never interacted with you before this thread, so how the hell
    >>> can it be?

    >>
    >> Our "friend" Peter Duniho seems to behave the same way towards many
    >> people, so it probably isn't personal. Just an attitude problem on his
    >> part.

    >
    > Why are you talking to yourself ?


    I'm not, you nincompoop, I'm talking to Harold Yarmouth. Isn't that obvious?
    zerg, Oct 26, 2008
    #18
  19. Lew wrote:
    > Lew wrote:
    >>> Let it go and stop the flame war, all right?

    >
    > Harold Yarmouth wrote:
    >> After you. You just insulted me yourself, and without cause.
    >>
    >> Why are you, Peter, and Arne suddenly posting a lot of completely
    >> off-topic posts and saying things about me that range from insulting
    >> to just plain strange? Why was Peter confrontational towards me
    >> without any apparent justification?


    (but Lew doesn't choose to answer any of these questions...)
    Harold Yarmouth, Oct 27, 2008
    #19
  20. Arne Vajhøj wrote:
    > You will need a large harddrive to keep a killfile with all his
    > aliases !


    I don't have any aliases. What do you think I am, some sort of spy?

    Hardly. I'm just an ordinary Java programmer. Quite boring, really.
    Harold Yarmouth, Oct 27, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    2
    Views:
    741
    Thomas Weidenfeller
    Oct 8, 2003
  2. hilz
    Replies:
    2
    Views:
    1,256
  3. SPG
    Replies:
    0
    Views:
    355
  4. news.skynet.be
    Replies:
    0
    Views:
    563
    news.skynet.be
    Mar 25, 2005
  5. fiziwig
    Replies:
    10
    Views:
    2,337
    Thomas Weidenfeller
    Aug 14, 2006
Loading...

Share This Page