• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Area of a Polygon

 
Patrick Thorse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get the area of a polygon? Seems like there should be a way to do that but I haven't found ANYTHING.........
Seems like there should be a polygon.getArea command?
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Patrick,
This is a function that would return the area of a Polygon whose vertices are given as the first parameter and the no. of sides is given as the second parameter.

-------------
Amit
[This message has been edited by Amit Agarwal (edited July 01, 2001).]
 
Patrick Thorse
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
Thank you very much. The area function worked perfect!
One more question. I have an applet that allows me to draw a polygon and then edit the polygon by 'tugging' on each of the nodes to change the geometry of the polygon. How do I refresh the screen without using paint()? After I move the nodes around, graphics remain on the screen that are not desired. If I minimize the browser window and then maximize it, the screen looks correct, with the old graphics removed.
Thanks,
Patrick
[This message has been edited by Patrick Thorse (edited July 03, 2001).]
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just call repaint() on the panel (or applet) you want to redraw. If you're using the AWT (not Swing) you might want to add a back-buffer to get rid of flickering.
Daniel
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patrick,
In your paint() add a statement to clear the panel in the beginning and redraw the polygon etc. use g.clearRect(0,0,getWidth(),getHeight()); if you have a background color, set the color and instead of clearRect() use fillRect(). Use double buffering in swing to get flicker free drawing.
Amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic