• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

flip Graphics2D.fillArc shape

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ended up drawing a triangle instead of attempting to rotate the ark - used GeneralPath api.
 
reply
    Bookmark Topic Watch Topic
  • New Topic