BafflinTransform

Discussion in 'Java' started by bob smith, Oct 3, 2012.

  1. bob smith

    bob smith Guest

    Am I the only one who gets incredibly confused by AffineTransform?

    I never know when to preConcatenate or concatenate. Then I try both possibilities, and a lot of times neither one produces my desired result.

    Any tips?
     
    bob smith, Oct 3, 2012
    #1
    1. Advertising

  2. bob smith

    markspace Guest

    On 10/3/2012 7:58 AM, bob smith wrote:
    > Am I the only one who gets incredibly confused by AffineTransform?
    >
    > I never know when to preConcatenate or concatenate. Then I try both
    > possibilities, and a lot of times neither one produces my desired
    > result.
    >
    > Any tips?



    I suspect some math is involved. :)


    Seriously, it's matrix algebra, and the formulas are given in each
    method description. You need to work out what it is you are actually
    doing first. Which you haven't told us, so I'm assuming that's the problem.
     
    markspace, Oct 3, 2012
    #2
    1. Advertising

  3. bob smith

    Lew Guest

    markspace wrote:
    > bob smith wrote:
    >> Am I the only one who gets incredibly confused by AffineTransform?


    No, but that isn't necessarily a reflection on the class.

    >> I never know when to preConcatenate or concatenate. Then I try both
    >> possibilities, and a lot of times neither one produces my desired
    >> result.


    http://sscce.org/

    "Hey, doctor, I keep trying to get healthy. I've tried medicine and I've tried
    exercise, and neither one produces my desired result."

    >> Any tips?


    Ask smarter questions.

    > I suspect some math is involved. :)
    >
    > Seriously, it's matrix algebra, and the formulas are given in each
    > method description. You need to work out what it is you are actually
    > doing first. Which you haven't told us, so I'm assuming that's the problem.


    So show us what you're trying to accomplish, what you've written as an SSCCE, and
    what precisely, with copied and pasted output, what differs from your precise
    expectations.

    --
    Lew
     
    Lew, Oct 3, 2012
    #3
  4. On Wed, 3 Oct 2012 10:41:15 -0700 (PDT), Lew <>
    wrote:

    >markspace wrote:
    >> bob smith wrote:
    >>> Am I the only one who gets incredibly confused by AffineTransform?

    >
    >No, but that isn't necessarily a reflection on the class.
    >
    >>> I never know when to preConcatenate or concatenate. Then I try both
    >>> possibilities, and a lot of times neither one produces my desired
    >>> result.

    >
    >http://sscce.org/
    >
    >"Hey, doctor, I keep trying to get healthy. I've tried medicine and I've tried
    >exercise, and neither one produces my desired result."
    >
    >>> Any tips?

    >
    >Ask smarter questions.


    Besides SSCCE, there is
    http://www.catb.org/~esr/faqs/smart-questions.html
    How To Ask Questions The Smart Way
    by Eric Steven Raymond
    It discusses at length how to properly ask technical questions.

    The main benefit of following it is that people will have more,
    relevant details and stand a better chance of knowing what you are
    discussing and what might be done about.

    A quieter, but more powerful benefit, is that to ask a technical
    question properly, you have to think about your problem in a
    structured manner, and often, this can lead to you being able to solve
    the problem yourself.

    [snip]

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Oct 3, 2012
    #4
  5. bob smith

    Jeff Higgins Guest

    On 10/03/2012 10:58 AM, bob smith wrote:
    > Am I the only one who gets incredibly confused by AffineTransform?


    According to the docs:
    concatenate [this] = [this] x [Tx]
    preconcatenate [this] = [Tx] x [this]

    >
    > I never know when to preConcatenate or concatenate. Then I try both possibilities, and a lot of times neither one produces my desired result.
    >
    > Any tips?
     
    Jeff Higgins, Oct 3, 2012
    #5
  6. bob smith

    Lew Guest

    Jeff Higgins wrote:
    > bob smith wrote:
    >> Am I the only one who gets incredibly confused by AffineTransform?

    >
    > According to the docs:
    > concatenate [this] = [this] x [Tx]


    <http://docs.oracle.com/javase/7/docs/api/java/awt/geom/AffineTransform.html#concatenate(java.awt.geom.AffineTransform)>

    > preconcatenate [this] = [Tx] x [this]


    <http://docs.oracle.com/javase/7/docs/api/java/awt/geom/AffineTransform.html#preConcatenate(java.awt.geom.AffineTransform)>

    >> I never know when to preConcatenate or concatenate. Then I try both possibilities,
    >> and a lot of times neither one produces my desired result.


    If neither produces the desired result, then it isn't the choice of method that is the problem.

    >> Any tips?


    --
    Lew
    Build a man a fire and you warm him for an hour.
    Set a man on fire and you warm him for the rest of his life.
     
    Lew, Oct 3, 2012
    #6
  7. bob smith

    Roedy Green Guest

    On Wed, 3 Oct 2012 07:58:04 -0700 (PDT), bob smith
    <> wrote, quoted or indirectly quoted someone
    who said :

    >Am I the only one who gets incredibly confused by AffineTransform?
    >
    >I never know when to preConcatenate or concatenate. Then I try both possibilities, and a lot of times neither one produces my desired result.
    >
    >Any tips?


    see http://mindprod.com/jgloss/affinetransform.html

    It has been a while since I wrote it, but it might help.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    The iPhone 5 is a low end Rolex.
     
    Roedy Green, Oct 4, 2012
    #7
  8. bob smith

    Arne Vajhøj Guest

    On 10/3/2012 1:41 PM, Lew wrote:
    > markspace wrote:
    >> bob smith wrote:
    >>> Am I the only one who gets incredibly confused by AffineTransform?

    >
    > No, but that isn't necessarily a reflection on the class.
    >
    >>> I never know when to preConcatenate or concatenate. Then I try both
    >>> possibilities, and a lot of times neither one produces my desired
    >>> result.

    >
    > http://sscce.org/
    >
    > "Hey, doctor, I keep trying to get healthy. I've tried medicine and I've tried
    > exercise, and neither one produces my desired result."
    >
    >>> Any tips?

    >
    > Ask smarter questions.
    >
    >> I suspect some math is involved. :)
    >>
    >> Seriously, it's matrix algebra, and the formulas are given in each
    >> method description. You need to work out what it is you are actually
    >> doing first. Which you haven't told us, so I'm assuming that's the problem.

    >
    > So show us what you're trying to accomplish, what you've written as an SSCCE, and
    > what precisely, with copied and pasted output, what differs from your precise
    > expectations.


    Hm.

    If the original poster has a limited number of specific
    problems, then producing a SSCCE is a very good thing.

    But I don't see any indications of that.

    To me it seems as if the original poster in general find
    it difficult to understand how to get it right (besides trial
    and error).

    It is not a SSCCE'able problem, because it is not about
    specific code.

    Instead it is about concepts and principles.

    Arne
     
    Arne Vajhøj, Oct 4, 2012
    #8
  9. On Wed, 03 Oct 2012 21:36:38 -0400, Arne Vajhøj <>
    wrote:

    [snip]

    >Hm.
    >
    >If the original poster has a limited number of specific
    >problems, then producing a SSCCE is a very good thing.
    >
    >But I don't see any indications of that.
    >
    >To me it seems as if the original poster in general find
    >it difficult to understand how to get it right (besides trial
    >and error).
    >
    >It is not a SSCCE'able problem, because it is not about
    >specific code.
    >
    >Instead it is about concepts and principles.


    It is still SSCCE, just not in code.

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Oct 4, 2012
    #9
  10. bob smith

    Jeff Higgins Guest

    On 10/03/2012 09:36 PM, Arne Vajhøj wrote:
    >>> bob smith wrote:



    > Hm.
    >
    > If the original poster has a limited number of specific
    > problems, then producing a SSCCE is a very good thing.
    >
    > But I don't see any indications of that.
    >
    > To me it seems as if the original poster in general find
    > it difficult to understand how to get it right (besides trial
    > and error).
    >


    To me it seems rather the bob is conducting a poll or troll.
    >>>> Am I the only one who gets incredibly confused by AffineTransform?


    > It is not a SSCCE'able problem, because it is not about
    > specific code.
    >
    > Instead it is about concepts and principles.
    >
    > Arne
    >
    >
    >
     
    Jeff Higgins, Oct 4, 2012
    #10
  11. bob smith

    bob smith Guest

    On Wednesday, October 3, 2012 10:46:00 AM UTC-5, markspace wrote:
    > On 10/3/2012 7:58 AM, bob smith wrote:
    >
    > > Am I the only one who gets incredibly confused by AffineTransform?

    >
    > >

    >
    > > I never know when to preConcatenate or concatenate. Then I try both

    >
    > > possibilities, and a lot of times neither one produces my desired

    >
    > > result.

    >
    > >

    >
    > > Any tips?

    >
    >
    >
    >
    >
    > I suspect some math is involved. :)
    >
    >
    >
    >
    >
    > Seriously, it's matrix algebra, and the formulas are given in each
    >
    > method description. You need to work out what it is you are actually
    >
    > doing first. Which you haven't told us, so I'm assuming that's the problem.


    It seems like when I want to "tack on" an operation, it is actually a preConcatenate.

    This is counterintuitive to me.

    Also, when you are just doing commutative operations, like just translation, it doesn't matter whether you preConcatenate or concatenate.

    What happened was I started with just translations and was concatenating.

    Then, I added rotation, and it did not work right whether I preConcatenated or concatenated. The issue was that I should have been preConcatenating the translations that I had already programmed in.
     
    bob smith, Oct 4, 2012
    #11
  12. On Thu, 04 Oct 2012 03:26:41 -0400, Jeff Higgins
    <> wrote:

    >On 10/03/2012 09:36 PM, Arne Vajhøj wrote:
    >>>> bob smith wrote:


    [snip]

    >To me it seems rather the bob is conducting a poll or troll.
    > >>>> Am I the only one who gets incredibly confused by AffineTransform?


    Oh, come off it. Taking the literal meaning when it is rather
    obviously not intended is silly.

    [snip]

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Oct 4, 2012
    #12
  13. On Thu, 4 Oct 2012 07:22:30 -0700 (PDT), bob smith
    <> wrote:

    [snip]

    >It seems like when I want to "tack on" an operation, it is actually a preConcatenate.
    >
    >This is counterintuitive to me.
    >
    >Also, when you are just doing commutative operations, like just translation, it doesn't matter whether you preConcatenate or concatenate.


    Matrix multiplication is NOT commutative.

    [snip]

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Oct 4, 2012
    #13
  14. In article <>,
    Gene Wirchenko <> wrote:

    > On Thu, 4 Oct 2012 07:22:30 -0700 (PDT), bob smith
    > <> wrote:
    >
    > [snip]
    >
    > > It seems like when I want to "tack on" an operation, it is
    > > actually a preConcatenate.
    > >
    > > This is counterintuitive to me.
    > >
    > > Also, when you are just doing commutative operations,
    > > like just translation, it doesn't matter whether you
    > > preConcatenate or concatenate.

    >
    > Matrix multiplication is NOT commutative.
    >
    > [snip]


    Absolutely correct, as well as pithy. Conceptually, it may help
    to think of a series of (post-) concatenated transformations as
    having been applied in a last-specified-first-applied order. In
    the example cited below, a small, U-shaped Polygon is centered
    about the origin. The following transform rotates, scales and
    translates the Polygon in the (apparent) reverse of program
    order:

    AffineTransform at = new AffineTransform();
    at.translate(SIZE/2, SIZE/2);
    at.scale(60, 60);
    at.rotate(Math.PI/4);

    <https://sites.google.com/site/drjohnbmatthews/point-in-polygon>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Oct 4, 2012
    #14
  15. bob smith

    markspace Guest

    On 10/4/2012 10:58 AM, John B. Matthews wrote:

    > In article <>,
    >>
    >> Matrix multiplication is NOT commutative.
    >>
    >>


    > Absolutely correct, as well as pithy. Conceptually, it may help
    > to think of a series of (post-) concatenated transformations as
    > having been applied in a last-specified-first-applied order.



    Another rule of thumb is that scaling and rotating tend to occur around
    the origin, not the translation point. So if you scale or rotate an
    already-translated AffinceTransform, you might get unintended results.

    The method I'm used to from 3D graphics is to translate any objects back
    to the origin, scale and rotate, then translate them back to their
    original/intended point in space. It's a literal three step process;
    you can't put all that together in one matrix.

    Given that AffineTransforms are 2D transforms, some results might be
    different than the 3D equivalents. Like I said, some math might be
    involved here.
     
    markspace, Oct 4, 2012
    #15
  16. bob smith

    Lew Guest

    Arne Vajhøj wrote:
    > Lew wrote:
    >>> bob smith wrote:
    >>>> Am I the only one who gets incredibly confused by AffineTransform?

    >
    >> No, but that isn't necessarily a reflection on the class.

    >
    >>>> I never know when to preConcatenate or concatenate. Then I try both
    >>>> possibilities, and a lot of times neither one produces my desired
    >>>> result.

    >
    >> http://sscce.org/

    >

    .. . .
    >> So show us what you're trying to accomplish, what you've written as an SSCCE, and
    >> what precisely, with copied and pasted output, what differs from your precise
    >> expectations.

    >
    > Hm.
    >
    > If the original poster has a limited number of specific
    > problems, then producing a SSCCE is a very good thing.
    > But I don't see any indications of that.


    Then you missed what you quoted:

    >>>> Then I try both possibilities, and a lot of times neither one producesmy desired
    >>>> result.


    > To me it seems as if the original poster in general find
    > it difficult to understand how to get it right (besides trial
    > and error).
    >
    > It is not a SSCCE'able problem, because it is not about
    > specific code.
    >
    > Instead it is about concepts and principles.


    He mentioned specific code, but he didn't show it.

    I asked him to show what he tried, as he claimed he'd tried it.

    That's pretty damned specific.

    --
    Lew
     
    Lew, Oct 4, 2012
    #16
  17. On Thu, 04 Oct 2012 13:58:13 -0400, "John B. Matthews"
    <> wrote:

    >In article <>,
    > Gene Wirchenko <> wrote:
    >
    >> On Thu, 4 Oct 2012 07:22:30 -0700 (PDT), bob smith
    >> <> wrote:
    >>
    >> [snip]
    >>
    >> > It seems like when I want to "tack on" an operation, it is
    >> > actually a preConcatenate.
    >> >
    >> > This is counterintuitive to me.
    >> >
    >> > Also, when you are just doing commutative operations,
    >> > like just translation, it doesn't matter whether you
    >> > preConcatenate or concatenate.

    >>
    >> Matrix multiplication is NOT commutative.
    >>
    >> [snip]

    >
    >Absolutely correct, as well as pithy. Conceptually, it may help


    Yes to the first, because I did not say much. I did not intend
    the pithy. I took one course that dealt with graphics
    transformations. The material was not covered as well as it could
    have been. Preferring not to misstate, I kept my statement short.

    Maybe, OP is going through what I did. I think he might benefit
    from some study of matrix algebra.

    [snip]

    Sincerely,

    Gene Wirchenko
     
    Gene Wirchenko, Oct 4, 2012
    #17
  18. bob smith

    Arne Vajhøj Guest

    On 10/4/2012 3:26 AM, Jeff Higgins wrote:
    > To me it seems rather the bob is conducting a poll or troll.


    Why?

    Problems understanding that stuff is pretty common.

    Arne
     
    Arne Vajhøj, Oct 4, 2012
    #18
  19. In article <k4kldp$g1q$>, markspace <-@.> wrote:

    > On 10/4/2012 10:58 AM, John B. Matthews wrote:
    >
    > > In article <>,
    > >>
    > >> Matrix multiplication is NOT commutative.
    > >>

    > > Absolutely correct, as well as pithy. Conceptually, it may help
    > > to think of a series of (post-) concatenated transformations as
    > > having been applied in a last-specified-first-applied order.

    >


    > Another rule of thumb is that scaling and rotating tend to occur
    > around the origin, not the translation point. So if you scale or
    > rotate an already-translated AffinceTransform, you might get
    > unintended results.


    Agree.

    > The method I'm used to from 3D graphics is to translate any objects
    > back to the origin, scale and rotate, then translate them back to
    > their original/intended point in space. It's a literal three step
    > process; you can't put all that together in one matrix.


    Why not? Isn't that what a method like the anchored rotate() below does?
    When it returns, the enclosing transform contains a single matrix that
    does all three things when applied to a graphics context or used to
    create a transformed Shape.

    public void rotate(double theta, double anchorx, double anchory) {
    translate(anchorx, anchory);
    rotate(theta);
    translate(-anchorx, -anchory);
    }

    > Given that AffineTransforms are 2D transforms, some results might be
    > different than the 3D equivalents. Like I said, some math might be
    > involved here.


    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Oct 5, 2012
    #19
  20. bob smith

    markspace Guest

    On 10/4/2012 6:23 PM, John B. Matthews wrote:

    > In article <k4kldp$g1q$>, markspace <-@.> wrote:
    >> you can't put all that together in one matrix.



    > Why not? Isn't that what a method like the anchored rotate() below does?



    What I was trying to say, and did say in fact, was that you cannot
    multiply out the three steps into a single matrix. Which is exactly
    what I quoted above. You apparently read "matrix" as "method" and
    thought I was talking about something else.

    Yes, you can easily make a single method. You still need a minimum of
    three matrix operations to accomplish the goal, however.
     
    markspace, Oct 5, 2012
    #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.

Share This Page