Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (780) Games in Android Showcase (233) games submitted by our members Games in WIP (857) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 area of an Area for Qix  (Read 1457 times) 0 Members and 1 Guest are viewing this topic.
pin_kushn

Senior Newbie

Java games rock!

 « Posted 2006-05-17 12:45:39 »

I am emulating an old arcade game: I think it was called Qix.  The player gradually "fills in" the game screen.  I have instances of both Polygon and Area that encapsulate the area that the player has filled in, but I can't figure out how to get an int or a double that represent the actual number of pixels contained by an Area or Polygon instance.  Any pointers?
ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

 « Reply #1 - Posted 2006-05-17 14:44:36 »

Once you know how to compute the area of a triangle, you can subdivide your polygon to find the total area.

Basically, take one vertex A, and for each edge B->C in the polygon, compute the area of the triangle formed by ABC, and sum the results.

This, however, will only work for convex polygons. To handle concave polygons you need to do a bit more work. For each edge B->C, you check which side A falls on, and either add or subtract the area of the triangle to the total.

For instance, assuming you are iterating through the edges in a counter-clockwise direction, if A lies on the left hand side of B->C, you add the area of the triangle ABC, if on the right hand side, you subtract.
pin_kushn

Senior Newbie

Java games rock!

 « Reply #2 - Posted 2006-05-17 14:58:58 »

Excellent.  Thanks.  The link to the Line2D static method is a nice added bonus: didn't know about that.
Pages: [1]
 ignore  |  Print

 hadezbladez (748 views) 2018-11-16 13:46:03 hadezbladez (388 views) 2018-11-16 13:41:33 hadezbladez (740 views) 2018-11-16 13:35:35 hadezbladez (199 views) 2018-11-16 13:32:03 EgonOlsen (2399 views) 2018-06-10 19:43:48 EgonOlsen (2579 views) 2018-06-10 19:43:44 EgonOlsen (1485 views) 2018-06-10 19:43:20 DesertCoockie (2148 views) 2018-05-13 18:23:11 nelsongames (1966 views) 2018-04-24 18:15:36 nelsongames (2647 views) 2018-04-24 18:14:32
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org