Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (577) Games in Android Showcase (156) games submitted by our members Games in WIP (626) 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 736 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

You cannot reply to this message, because it is very, very old.

 ClaasJG (41 views) 2015-04-30 20:33:25 Riven (24 views) 2015-04-30 13:25:12 ClaasJG (46 views) 2015-04-27 13:36:51 BurntPizza (51 views) 2015-04-23 03:42:11 theagentd (52 views) 2015-04-22 16:23:07 Riven (65 views) 2015-04-16 10:48:47 Duke0200 (76 views) 2015-04-16 01:59:01 Fairy Tailz (60 views) 2015-04-14 20:13:12 Riven (64 views) 2015-04-12 21:36:37 bus hotdog (90 views) 2015-04-10 02:39:32
 theagentd 24x BurntPizza 19x Spasi 16x kingroka123 11x alwex 11x wessles 11x Hanksha 10x Ecumene 8x ra4king 8x princec 6x chrislo27 6x kevglass 6x Riven 5x EgonOlsen 5x trollwarrior1 5x KevinWorkman 4x
 List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00
 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