Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (538) Games in Android Showcase (132) games submitted by our members Games in WIP (600) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D Polygon's and waypoints  (Read 2163 times) 0 Members and 1 Guest are viewing this topic.
Lemon

Senior Newbie

Java games rock!

 « Posted 2005-09-23 08:19:00 »

Hey

I have a problem with a current project I'm working on and I havn't been able to come up with a decent solution for quite some time now

The problem is this:

I have a Polygon object in two dimensions and I wish to find the Waypoint objects for this Polygon object.  The  waypoints are positioned such that if each waypoints was connected to its neighbor they should form a new Polygon whose lines are parallel to the original Polygon and are 10 units away.

i have tried finding the centre and extending a line from the centre through each point of the polygon but this does not work for Polygons which are convex or have an irregular shape. Surely there is an easy solution to this problem  . Efficiency is not terribly important as the waypoint positions are precalculated in my application.

Simon

Riven
« League of Dukes »

« JGO Overlord »

Medals: 840
Projects: 4
Exp: 16 years

 « Reply #1 - Posted 2005-09-23 09:20:46 »

Don't use a center-point, that requires all polygon-points to be at the same distance fomr the center, which is rarely the case.

Calculate the 2D normal of each edge, go to the center of the edge, follow your normal up to 10 units, make the parallel lines (infinite length) and find where they intersect the neighbour parallel-line, which will be a waypoint.

Picture says more than a thousand words, so here you go:

Hope this helps.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Lemon

Senior Newbie

Java games rock!

 « Reply #2 - Posted 2005-09-23 10:01:47 »

I will try that

Thanks
Jeff

JGO Coder

Got any cats?

 « Reply #3 - Posted 2005-09-23 22:32:09 »

I actually wrote code that did exactly this awhile ago.

Slight difference in order that coems otu to the same thing:  I found the normals of the two conencting edges and averged them to get a normal at the corner and then multipled that unit vector by the required distance from the corner to find the new corner point.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Riven
« League of Dukes »

« JGO Overlord »

Medals: 840
Projects: 4
Exp: 16 years

 « Reply #4 - Posted 2005-09-23 23:40:38 »

Well that would have been easier yes, but he wanted parallel lines, that's why it's all slightly more complex.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Jeff

JGO Coder

Got any cats?

 « Reply #5 - Posted 2005-09-24 04:31:41 »

Well that would have been easier yes, but he wanted parallel lines, that's why it's all slightly more complex.

ah, missed that requirement.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Lemon

Senior Newbie

Java games rock!

 « Reply #6 - Posted 2005-09-30 03:35:23 »

Well I've got that sorted and everything is working well.

I've got another question though, this ones involving threads.

I'm quite confused about how I should be going about this. Should I create a new class that holds all the data and is a MouseListener and ActionListener and have both this class and the LoadingScreen within the JPanel?

Thanks
Simon
Riven
« League of Dukes »

« JGO Overlord »

Medals: 840
Projects: 4
Exp: 16 years

 « Reply #7 - Posted 2005-09-30 09:08:35 »

Yes, definitly seperate your data from your GUI. You'll save yourself from a lot of trouble and it'll make your application a lot clearer. Once you seperated it, you'll find it much eachier to do your threading.

Basicly you want this:
periodicly check (every 100ms?)  that new thread changed some variable - possibly now containing the result of the calculation - to notify it's finished.
when you found that the thread has done it's job, grab the results from that variable and paint it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Pages: [1]
 ignore  |  Print

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

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 rwatson462 (29 views) 2014-12-15 09:26:44 Mr.CodeIt (20 views) 2014-12-14 19:50:38 BurntPizza (40 views) 2014-12-09 22:41:13 BurntPizza (75 views) 2014-12-08 04:46:31 JscottyBieshaar (37 views) 2014-12-05 12:39:02 SHC (50 views) 2014-12-03 16:27:13 CopyableCougar4 (47 views) 2014-11-29 21:32:03 toopeicgaming1999 (113 views) 2014-11-26 15:22:04 toopeicgaming1999 (100 views) 2014-11-26 15:20:36 toopeicgaming1999 (30 views) 2014-11-26 15:20:08
 LiquidNitrogen 33x basil_ 31x HeroesGraveDev 28x Rayvolution 27x BurntPizza 20x appel 17x kevglass 16x kpars 14x gouessej 13x Riven 13x Gibbo3771 13x Ecumene 11x NegativeZero 11x Spasi 11x SHC 10x pitbuller 9x
 Resources 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:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50
 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