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.

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 rankings!

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!

Currently I have most of my application inside a JPanel. Then JPanel is handling MouseEvents, ActionEvents etc. and is storing all the information about my waypoints. At the moment there is a button which generates polygons and their respective waypoints. When I click this there is a delay of about 3 -5 seconds as the new information is generated. I'm attempting to thread the application so that I can have an animated loading bar display on the JPanel while the waypoints are being loaded. This is the part where I'm stuck. Where do I create the threads? I currently have a simple LoadingScreen that implements Runnable and has a paint(Graphics g) method. But how do I go about threading the JPanel. Since all the data is stored in the JPanel I need the run() method to be within the JPanel. But the LoadingScreen will require the JPanel to paint.

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?

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:onClick -> spawn new Thread that does the heavy task.periodicly check (every 100ms?) that new thread changed some variable - possibly now containing the result of the calculation - to notify it's finished.in between your checks update the loading-bar.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 rankings!

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