The moose likes Swing / AWT / SWT and the fly likes flip Graphics2D.fillArc shape Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "flip Graphics2D.fillArc shape" Watch "flip Graphics2D.fillArc shape" New topic

flip Graphics2D.fillArc shape

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hi everyone,
I have a shape, representing an hour hand of a clock. I draw it this way:

The trouble is that the pointy part of the shape is at the center of my clock. I have been attempting to flip it with Graphics2D.translate and Graphics2D.rotate, but no success. Seems like a simple task, but maybe I'm underestimating it. Any ideas?
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

Seems like you don't understand what fillArc() method does, so you should check the API or look for a tutorial.
You might find GeneralPath class suitable for your needs, because it enables you to draw geometry path of your own choice. It might involve some more calculations, though, to draw it properly in your application. Here you can find some basic examples.

The quieter you are, the more you are able to hear.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Yes, I realized I need the shape separate from the plain. At this point I'm straggling with AffineTransform API. I see AffineTransform has a type FLIP, but I have not yet figured out how to use it. If anyone has some experience with AffineTransform, please post... Here is what I have now:

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38007
I shall move this discussion to our GUIs forum, where I think it would fit better.

Don’t appy an AffineTransform to your Graphics object. Copy the Graphics object, which I think you can do with its create() method, and apply all the affine transforms to that object. The reason is that some transforms cannot readily be undone to yield exactly the original form of the object. Scale, rotate and translate are not too bad for that, but shear is the one that causes problems.
Look for the methods in Graphics2D which apply affine transforms by themselves: it has scale translate rotate and shear methods already.
The hard part is working out what to rotate around. Try this sort of thingObviously the arithmetic about the rotation can be changed if you want to start at 12o’clock and go clockwise. I have believed you about fillArc(), though that would appear to be the wrong method, and you will need to use something else.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I'm not sure why, but when I use the code posted (Campbell Ritchie), or when I use AffineTransform.setToRotation - in both cases I have the same result: I have no arks drawn with these calls and there are no errors at all. Maybe they get so misplaced, that become not visible, I'm not sure.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I ended up drawing a triangle instead of attempting to rotate the ark - used GeneralPath api.
I agree. Here's the link: http://aspose.com/file-tools
subject: flip Graphics2D.fillArc shape
Similar Threads
Casting a extended class
flipping bytes
Finding the color of a pixel
Animating independent objects?