Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4556074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:18:55+00:00 2026-05-21T17:18:55+00:00

I’m looking for a way to combine affine transforms in such a way so

  • 0

I’m looking for a way to combine affine transforms in such a way so that the effect is equivalent to using each transform to manipulate a shape in succession. The problem is that if I simply concatenate the transforms, then each successive transform’s effect is interpreted in the existing transform’s co-ordinate space.

For example, consider a square around the origin (-50,-50, 100,100). I want to rotate it, and then translate it down 100px. If I take a transform and rotate and then translate, the translation gets interpreted in the rotated coordinates. Instead, if I transform the shape itself to rotate it, and then transform that shape again to translate it, both translations are interpreted in the “normal” un-translated plane, and it gives me what I want.

The problem is that for what I’m doing many transforms may take place, each of which needs to be interpreted in the normal coordinate plane, but I don’t want to store a stack of transforms, nor can I simply keep manipulating a shape, because I need to at any time be able to create the final transformed shape from the original starting shape.

Example: normal concatenation on the left, successive transforms on the right

I’m aware that for this simple example if I did the translate before the rotate I’d get the same result, but that’s missing the point. I’m dealing with an arbitrary set of successive scale, translate, and rotate transforms, so simply putting them in a certain order doesn’t cut it.

I have an inkling that there should be a way to concatenate transforms in such a way that you modify the new transform before you concatenate it, correcting for the existing transform so that the effect is that the new transform appears to have been applied as if it were referencing the un-transformed coordinate plane. For example, if you translate by (70.7, 70.7) in the above example instead of (0,100), the result becomes equivalent. I just can’t seem to figure out what the math is to figure out in general how to alter the new transform so it works out correctly.

Thanks for reading – hope this made sense. Heres the source of the example that created the screenshot:

public class TransformExample extends JPanel {

@Override
protected void paintComponent(Graphics _g) {
    super.paintComponent(_g);
    Graphics2D g = (Graphics2D) _g;
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.translate(150, 100); // translate so we can see method 1 clearly
    paintConcatenate(g);
    g.translate(200, 0); // translate again so we can see method 2 to the right of method 1
    paintSuccessive(g);
}

private void paintConcatenate(Graphics2D g) {
    AffineTransform tx = new AffineTransform();
    Shape shape = new Rectangle(-50, -50, 100, 100);

    // Draw the 3 steps, altering the transform each time
    draw(g, shape, tx, Color.GRAY);
    tx.rotate(Math.PI / 4);
    draw(g, shape, tx, Color.GREEN);
    tx.translate(70.7, 70.7);
    draw(g, shape, tx, Color.PINK);
}

private void paintSuccessive(Graphics2D g) {
    Shape shape = new Rectangle(-50, -50, 100, 100);

    // Draw the 3 steps, altering the shape each time with a new transform
    draw(g, shape, null, Color.GRAY);
    shape = AffineTransform.getRotateInstance(Math.PI / 4).createTransformedShape(shape);
    draw(g, shape, null, Color.GREEN);
    shape = AffineTransform.getTranslateInstance(0, 100).createTransformedShape(shape);
    draw(g, shape, null, Color.PINK);
}

private void draw(Graphics2D g, Shape shape, AffineTransform tx, Color color) {
    if (tx != null) {
        shape = tx.createTransformedShape(shape);
    }
    g.setColor(color);
    g.fill(shape);
}

public static void main(String[] args) {
    JFrame f = new JFrame("Transform Example");
    f.setSize(500, 350);
    f.setContentPane(new TransformExample());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

}

(I’m working with Java2D, although I don’t think the language or 2d library is all that pertinent here.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:18:56+00:00Added an answer on May 21, 2026 at 5:18 pm

    I suggest you to keep track of some absolute values and then do less transformations as you can.

    For example, store the translation matrix and the rotation angle around the origin.

    int translate[2];
    int rotate;
    

    Now, suppose that you want to rotate around its center and then translate the object somewhere, and then rotate it again under its center.
    Because with affine transformations, rotation matrix aren’t commutative, so if you apply a rotation,translation, rotation you’ll get an wrong result.

    But you can simply sum the rotation angle of the first and third rotation, and apply a single rotation and then the translation.

    Hope to be clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.