How can I draw a (dynamic) regular polygon on a map?

I have been having a go at drawing a regular polygon, in this example a hexagon, on a map. Not a big one, only 400m radius. I am using the haversine (great circle) formula to generate the points of the polygon from a centre point of coordinates.

The use of the haversine formula seems to be causing a problem in that the polygon is stretched/squashed, and not regular.

RegularPolygon.aia (4.9 KB)

I have tried modifying the distance for each point, but this just produces an oddly shaped polygon, or exacerbates the squashing.
I have either missed something, or work is needed either on the formula or elsewhere ? Do I really need a flat earth solution ? :wink:

Any help or suggestions much appreciated.

ref1, ref2

Possible reasons:

-The OpenStreetMap map is a Mercator Projection. That means there is some distortion when plotting on the may using x and y coordinates The map you see is NOT a Flat map. In this case the North-South coordinates are 'stretched'. If you draw on a Flat map you might realize your expectations. Why? At the equator, a degree of longitude is the same as a degree of latitude , about 69 miles (111 km). But the width of the longitude separation decreases as you move closer to the north pole.

  • the precision of the points might be insufficient to resolve a regular polygon even on a Flat Map .. a guess but plotting on a Flat Map is what you have to do to see a regular polygon plotted on a surface without distortion.

  • your version of haversine may not be robust . I haven't had an opportunity to compare with my version of haversine. Movable Type Scripts is a regarded version of the haversine distance calculation so you should get reasonable results if you did the math coorectly.

  • at 43 N latitude (MIT) one deg of latitude is approximately 111.092 meters. You can check your math by building a hexagon using fixed points. It should be distorted on the Mercator Map Projection.

which is expected. but your hexagon is twice as wide as it it high, so I expect something is wrong with the math . What? At the moment too tired to calculate. :cry: Put a scale on your Map and it will be obvious. :slight_smile:


Having slept on it, I believe l may know what the problem is. Things to do, will report back.

Seemed to have fixed it. An issue with order of precedence in one of the formulas

y = sin θ ⋅ sin δ ⋅ cos φ1
x = cos δ − sin φ1 ⋅ sin φ2
λ2 = λ1 + atan2( y , x )


should be this

Hexagon at 100m

Hexagon at 2000m :slight_smile:

If you want your hexagon "inline" with the top and bottom of the map:


and my original objective (to draw a circle)

Correct Haversine formula as draggable blocks


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.