Doing one transform on a shape after another...

Hi - I am writing a program to create computer artwork and have run into a problem. If I start with a shape (such as a square) and then do a rotation on it I get a diamond... fine... but now what I want to do is stretch the diamond in the x and y directions. For this I'd use scale, but, my problem is that, because the coordinate system was shiftted by the first transform, when I scale in y (for example) the diamond doesn't become stretched, but instead stretches along the old co-ordinate system, so in fact you can see that it is in fact stretching the original square, rather than the new diamond.
I thought about creating a buffered image from the shape and then stretching that but it's not really great to do that in terms of the rest of my program. Is there any way of doing one transform and then resetting the co-ordinate system so that any further transform I do will apply to the new shape rather than the old one?
Thanks in advance for any help - I'm really stuck here and I can't believe that you can't do this in Java!
Olly

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import javax.swing.*;
public class TransformTest extends JPanel
    Shape shape;
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        if(shape == null)
            initShape();
        g2.draw(shape);
        double theta = -Math.PI/4.0;
        Rectangle r = shape.getBounds();
        AffineTransform at =
            AffineTransform.getRotateInstance(theta, r.getCenterX(), r.getCenterY());
        Shape diamond = at.createTransformedShape(shape);
        g2.setPaint(Color.red);
        g2.draw(diamond);
        double xScale = 1.5;
        double yScale = 1.0;
        r = diamond.getBounds();
        double x = (1.0 - xScale) * r.getCenterX();
        double y = (1.0 - yScale) * r.getCenterY();
        at.setToTranslation(x, y);
        at.scale(xScale, yScale);
        diamond = at.createTransformedShape(diamond);
        g2.setPaint(Color.blue);
        g2.draw(diamond);
    private void initShape()
        int w = getWidth();
        int h = getHeight();
        int s = Math.min(w,h)/3;
        int x = (w - s)/2;
        int y = (h - s)/2;
        shape = new Rectangle(x, y, s, s);
    public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(new TransformTest());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • Why does one movie rental start immediately and another after 15 hrs?

    Yesterday I rented a movie, actually two, via Apple TV2  and both started immediately and ran to finish without interruption. Today , after that experience, II tried to rent another movie and apple tv 2 tells me it will be ready in 15 hours. What is the deal?  can I get out of the rental, is thre any way to tell in advance of renting when it could be viewed? This makes movie rentals on Apple TV impractical.

    From the admin account:
    # Right click on the application
    # Select Properties
    # In the Compatibility tab, make sure that Privilege Level: "Run this program as Administrator" is not selected.

  • Invalid transform on JavaFX shape after creation

    Hello,
    I am working on a UI in JavaFX and create several instances of a custom control class. The control consists of a Pane which wraps several other containers, one of which contains a Circle shape.
    At one point, I instance this control and access the Circle shape directly. I transform it's center coordinates (which are always {0.0, 0.0} ) to Scene coordinates.  The problem is, the transformation always yields coordinates that correspond to the upper left corner of the control's root pane.
    In other words, it's as if the Circle is positioned at the upper left corner of the custom control (when, in fact, it's positioned near the lower right corner).
    I have other instanced controls already in the scene, and they do not have this issue - converting the Circle's coordinates to scene coordinates works as it should.
    It seems obvious that I'm accessing the Circle too soon - that perhaps the scene graph hasn't been fully traversed for the control and the Circle's position within the control's hierarchy hasn't been updated.  I've verified that my attempt to access the Circle's center coordinates occurs after the control's initialize() method is executed, so I'm at a bit of a loss to figure out how to ensure the control's scene graph has been fully updated before I try to manipulate the control...
    Any thoughts?

    You can read up on how to generate a layout pass.
    Most of the time, you don't need to generate a layout pass. 
    You could probably modify your logic so that an explicit layout pass request is not needed.

  • How does one clean out the trash, after putting in a time line file in?

    After cleaning out some old files, it was late one night that I put a old file from the Time Line into the trash.  Now how can this be FIXED?

    Time Line...? If you mean Time Machine, then you should only delete old backups and files using the Time Machine interface.
    If you did a NO NO and moved old Time Machine backups to the Trash using Finder? Then go to > Time Machine - Frequently Asked Questions 12 and scroll down to the section in gray for the solution.

  • Why does one set of clients out perform another?

    Greetings all -
    When I execute sqlplus using this query "select * from SYS.COL$ where rownum<=50000;" from our linux client it, takes 12 seconds. When I execute it from any of several of our solaris clients it takes close to a minute. So the linux client will run the above SQL faster than all the solaris clients by a multiple of 4 or 5 times. The linux (el x86-64) data servers and the sun clients are all in the same room. Some of the solaris clients are virtual (zones) on a SUN t5220 box. Other solaris clients are physical boxes (sparc SUNW,Sun-Fire-V245).
    The 2 linux dataservers are HP ProLiant DL380s. When one of these is used as a client and runs the SQL against the same database that the solaris clients are targeting it out performs the solaris clients significantly.
    So allow me to restate - when I run the query from dataserver_2 against the target database on dataserver_1, it takes 12 seconds. When I execute the query from any solaris client against the target database on dataserver_1, it takes over 50 seconds.
    We've also tested with a "back door" in place, putting the solaris client on the same network as the dataservers. This didn't make any difference. I've also tested by making changes to the kernal settings on the solaris client, bumping up the max-shm-memory parm from the default up to 7g and this also didn't help. The linux client which performs well is also a dataguard standby server. Why am I seeing such a difference in elapsed times to run this query - depending on which client I run it from? All the solaris clients query elapsed times are consistently around 55 seconds. When it runs from another linux client in a four miles away, it takes 38 seconds. What can I do to improve the performance for these solaris clients?
    A side note: running an "ssh scp" against a 1-gb file also takes inordinately long when the source or target is one of our solaris clients. Our UNIX support tells us this just indicates scp doesn't work so great on these clients.
    tia -
    Jim

    Hi Charles,
    Here's some representative trace output....
    <<<<<<<<<< snip from trace 10043 output from "good" client...(note the "ela" -elapsed- values are < 300
    FETCH #1:c=0,e=114,p=0,cr=4,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183488152138
    WAIT #1: nam='SQL*Net message from client' ela= 270 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488152432
    WAIT #1: nam='SQL*Net message to client' ela= 1 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488152460
    FETCH #1:c=0,e=24,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183488152476
    WAIT #1: nam='SQL*Net message from client' ela= 225 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488152721
    WAIT #1: nam='SQL*Net message to client' ela= 1 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488152748
    FETCH #1:c=0,e=23,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183488152763
    WAIT #1: nam='SQL*Net message from client' ela= 221 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488153003
    WAIT #1: nam='SQL*Net message to client' ela= 0 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183488153030
    FETCH #1:c=0,e=24,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183488153045
    <<<<<<<<<< snip from trace 10043 output from "bad" client...(note the "ela" -elapsed- values are all all > 800
    FETCH #1:c=0,e=24,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183823787134
    WAIT #1: nam='SQL*Net message from client' ela= 894 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823788051
    WAIT #1: nam='SQL*Net message to client' ela= 0 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823788079
    FETCH #1:c=0,e=25,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183823788095
    WAIT #1: nam='SQL*Net message from client' ela= 890 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823789010
    WAIT #1: nam='SQL*Net message to client' ela= 1 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823789038
    FETCH #1:c=0,e=24,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183823789054
    WAIT #1: nam='SQL*Net message from client' ela= 975 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823790051
    WAIT #1: nam='SQL*Net message to client' ela= 0 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1239183823790079
    FETCH #1:c=0,e=25,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,tim=1239183823790095
    The above pattern is repeated for 150,000 lines of trace output. There are no series of repeated "message from client" lines which might represent repeat ACKing if I understood you correctly.
    The "good" trace output file has 150,099 lines and "bad" trace output file has 150,092 lines. No extra ACKs in the bad - just much longer "SQL*Net message from client" elapsed times.
    I've just tested with arraysize set to 50000. No gain.
    I also set SDU to 32768 in both the client tnsnames file and the listener/sid_list. No gain.
    Thanks all for your helpful feedback.
    Jim

  • How does one copy a PDF file into another PDF document?

    I am trying to copy part of a PDF file into another PDF document. So far, the file will copy but will not paste into another PDF document. Any clues?

    You can't convert Photoshop to editiable InDesign (though there is a plugin from RecoSoft that claims to make editable ID files from PDF: http://www.recosoft.com/products/pdf2id/).
    About the best you can hope for is to leave pixel information in the Photoshop file (where it really belongs) and place that into an ID document, then set any type in ID.
    Peter

  • TS3938 How does one get the upgrades necessary after getting Lion when there is no upgrade for Real Player for Mac????

    Just got Lion. How can I get the upgrades necessary if there is no t one for Real Player for Mac????

    http://www.macupdate.com/app/mac/8428/realplayer-sp

  • How does one revert to original photo after corrections such as redeye assist?

    using common edit tools in Iphoto, I used redeye assist, and now cannot revert to orig. file
    so my picture looks like a raccoon....any helpful suggestion to gain original file again would
    be gratefully accepted...thanks!

    In iPhoto 9 (11) you need to use the Photos ➙ Revert to Original menu option.
    OT

  • How does one change library from 1,5 to 2,0?

    How does one transform 1.5 photo library to 2.0 library within Aperture 2.0?
    Thanks!

    Mitch Aunger wrote:
    and of course you have a backup of your library before you start... right???
    Of course - everyone uses Time Machine, right ?

  • How do i get music videos to play like the music does on my ipad, for example one right after another and shuffle

    I need to know how I can get the music videos on my IPad to play like the music does.  What I mean id setting up a playlist, shuffle, and have them play one right after another instead of going back to the main screen.

    At the top of the playlist where it shows the playlist title and the number of songs, there are two icons. Click the "play" triangle to add the entire playlist to "Up Next", or the "shuffle" symbol to do the same thing but in random order. But the currently playing track will stop playing, and all the songs in "Up Next" will be removed (replaced by the ones from this playlist).
    If you hold down the "option" key while clicking those icons, the currently playing song will continue playing, and the new playlist will be added to "Up Next" (above the songs that were already there).

  • How does one crop an .ai image to a defined shape?

    How does one crop an .ai image to a defined shape?
    In other words, I want to select and crop from a larger image an area such as a rectangle that I define.
    Right now, I try to select and crop a rectangular portion of an image but every shape that is even partially within the rectangle is selected both within and without the rectangle.
    I am using CS2 on a Mac.

    Clifford,
    I've figured out part 1, how to crop an image using a rectangle on  another layer.
    Then I did:
    To really get rid of the outlying parts, with the Clipping Mask still 
    selected you may:
    5) Choose anything but Normal in the Transparency palette dropdown 
    and Object>Flatten Transparency (just keep the defaults).
    The result was "Filter cannot complete because of unknown error"  FSpt
    Is this a bug, or is their a problem with the way I am following your 
    method?
    It is hard to say.
    It is more convenient to place the rectangle mentioned in 1) on the same layer; if you place the path(s) to define the Clipping Mask, the Clipping Mask and its contents will be on that layer, everything from lower layers being moved to it.
    What about 2) - 4)?
    It is easier to answer if you state what happens in the individual steps (repeated here):
    1) Create a rectangle on top of the image with the same size (you may use the Transform palette/panel to see the size, and to place it by);
    2) Create the cutout shape;
    3) Select 1) and 2) and Object>Compound Path>Make;
    4) Also select the image, and Object>Clipping Mask>Make.
    To really get rid of the outlying parts, with the Clipping Mask still selected you may:
    5) Choose anything but Normal in the Transparency palette dropdown and Object>Flatten Transparency (just keep the defaults).

  • Is it possible to play one music video after another in itunes/front row?

    Hi all. Can anyone help me with this problem? When I use the movie part of front row to watch and listen to music vids I have front row goes back to the movie menu after each video has ended. Is it at all possible to watch one video after another without having to scroll down to the next music video after each music video has finished playing? Not sure if im being incredibly dense but any help would be greatly appreciated. I have Apple Care and they have no idea what im on about!
    Thanks Rob

    I've been doing some experimenting on this. I made a smart playlist in iTunes to gather all my music videos (which I have previously tagged with 'VIDEO' in the comment field).
    In Frontrow, iTunes will not play the video at all- it just shows a single frame and plays the audio; in Movies, music videos, it will play one music video correctly, but then go back to the music video menu. This seems to be a known problem.
    My solution is to go back to the desktop and use iTunes in the old fashioned way! Selecting my new VIDEO smart playlist will play all my music videos in any order I like using the normal parameters i.e. random, alphabetical by artist, album, name etc..
    Hope this helps.

  • Load one swf after another?

    Hey!
    I've created a presentation in Flash that exceeds the maximum number of frames. I broke it up into a few different files, and now I need these .swfs to load one after another automatically, without prompting or clicking anything on the screen.
    The presentation is for an interpretation program at work and will be played for an audience several times a day. It was originally a 6-slide-projector presentation that I simplified, and this is the last step to replacing the old projection system altogether.
    Does anyone know how to solve my problem, as simply as possible?
    Thank you!

    you'll probably want to load them all at the start of you presentation so they're ready for display without waiting.
    so, use standard preloader code to load your swfs.  use a loop or dispatch an event to detect when one ends and another needs to start.

  • Why does the same RGB color appear lighter in one ai file and darker in another?

    Why does the same RGB color appear lighter in one ai file and darker in another??  I want to use the more vibrant color, but when I try to reproduce the same RGB color code in another Adobe Illustrator (ai) file, it shows up darker.  I printed the two files out, and you can see the difference in the print too.  I exported the color orginally as an eps file from an ArcGIS map.
    Any insight is greatly appreciated!
    Anne

    You illustrator files may have different color profiles attached.
    Set to show your color profile in the bottom left of each document by using the flyout menu >> show >> document color profile
    Then you can use edit >> assign profile to get them the same
    Yours are quite far off for RGB (which are usually close to each other for many profile due to wide gamut).  I question as Jacob did if one of your documents are in CMYK mode. Look in parenthesis after the document name at top of window.
    Check if view > proof setup is the same (do not use the uncoated profile as in my screenshot, that was only there cause of my testing)
    Make sure view >> proofs colors is checked or unchecked for both.
    To get them to print the same, check these settings are the same
    Sorry for all the screenshots, but hopefully one day we will see Adobe's complex color management united all in one window.

  • Songs Skip Forward One After Another/Sporadic and Out of Nowhere

    I have an older IPOD 40g that skips through songs, one after another, without playing anything, and seems to do it in any mode, especially in overall Shuffle mode. I have the "shuffle Songs" feature on, but other than that, it has a pretty standard set up.
    I have restored to the defaults, last week, and it started doing the wierd stuff again today.
    Sometimes I have a hard time getting it to unfreeze and reset as well.
    I appreciate any help.

    Have you tried Party Shuffle? If you control click on a track, you can choose "Play Next In Party Shuffle". I often listen the way you're describing. I start listening in Party Shuffle (which I have set to select from a specific playlist). When I am reminded of another song, I select the song and then choose Play Next in Party Shuffle. And so on.
    As for your second question, you could try moving your entire short playlist into Party Shuffle. Once that playlist was done, Party Shuffle would revert to it's normal selection criteria (you could set it to pull from your entire library or a specific playlist). Music would keep playing.
    Can you tell I like Party Shuffle?

Maybe you are looking for

  • Possible to back up volumes to different hard drives.

    I have multiple hard drives attached to my Mac Pro and all 4 internal slots are full. I would like Time Machine to copy different volumes to two different external hard drives. I can't buy a single hard drive big enough to handle backups of everythin

  • Working on KM Configuration iview to configure KM Services

    plz let me know if any steps not the links

  • JDBC Driver

    I am using JDBC driver ojdbc14.jar in my Spring application. The java version is 1.4.2 and the JDev version is 10.1.2. The application works perfectly. I do not specify Types.VARCHAR etc while doing the DML operations. It works perfectly on this Jdev

  • ORA-16005 : database requires recovery

    Following error occurred while trying to open oracle datababse in read only mode $ sqlplus /nolog SQL> connect /as sysdba connected SQL> SQL> startup nomount ORACLE instance started Total System Global Area 612368384 bytes Fixed Size 1281504 bytes Va

  • Modul Pool Screen

    Hi all, I am facing an issue in module pool. I have a screen in which all fields are mandatory. the issue is when I press Back button the system gives "Fill in all required fields". In this case this should not happen. If I have inserted any value an