This week's book giveaway is in the Security forum.We're giving away four copies of Penetration Testing Basics and have Ric Messier on-line!See this thread for details.
Win a copy of Penetration Testing Basics this week in the Security forum!

# flip Graphics2D.fillArc shape

liliya woland
Ranch Hand
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
Bartender
Posts: 825
5
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.

liliya woland
Ranch Hand
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
Sheriff
Posts: 50644
83
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
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
Posts: 134
I ended up drawing a triangle instead of attempting to rotate the ark - used GeneralPath api.