Drawing a polygon given multiple points

Curtis W. Ruck ruckc at YAHOO.COM
Tue Sep 26 19:44:12 EDT 2006


I did something like this where i took the input points in the order given, and then compared the angle measurements of the lines leaving each point.  If the angle measurement was not around 90 +- 10 degrees we flipped the last two coordinates.

We basically just did a little trigonometry.  I don't have the process i have here with me but it was fairly simple after i remembered my trig from college.

----- Original Message ----
From: Brian Krebs <brian.krebs at KORTERRA.COM>
To: MAPSERVER-DEV at LISTS.UMN.EDU
Sent: Tuesday, September 26, 2006 5:10:59 PM
Subject: [UMN_MAPSERVER-DEV] Drawing a polygon given multiple points




 
 

<!--

 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:blue;
text-decoration:underline;}
span.EmailStyle17
	{
font-family:Arial;
color:windowtext;}
 _filtered {
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{}
-->






I’ve ran into a situation where I have multiple
lat/long coordinates in no particular order and I need to use them to create a
polygon so there aren’t any intersecting lines.  The code I’ve
written so far loops through the coordinates and creates a new line point using
line.add(new pointObj(x, y, 0, 0)) for each one.  Unfortunately, there is
no guarantee that the data we receive from other companies is going to be in
any logical order.
 

  
 

As an example, say I had 4 points and I want to create a box:
 

If we receive them in the following order, we get a box. 
 

-2, 2
 

2, 2
 

2, -2
 

-2, -2
 

  
 

If we receive them in this order, we get an hourglass type
shape.
 

-2, 2
 

2, 2
 

-2, -2
 

2, -2
 

  
 

Is there any function or some simplified algorithm that will
put these coordinates into a proper order?  I need something that will
figure out the order no matter how many points there are.
 

  
 

Thanks
 







-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20060926/7070f06d/attachment.html


More information about the mapserver-dev mailing list