Andrei Zenoveiov
Andrei Zenoveiov

Reputation: 1

Calculate a Hexagon based on a point

this is my problem:

I need to determine the correct coordinates(Latitude,Longitude) of a hexagon/polygon. I have as inputs:

The steps taken:

  1. Given point is translated with the length of the radius, obtaining the first point: lat = lat + radius

  2. New coordinates are obtained (rad is the angle theta in radians)

    result.x = Math.cos(rad) * lat + Math.sin(rad) * lon;
    result.y = Math.cos(rad) * lon - Math.sin(rad) * lat ;

Problem: Setting the radius to 1 returns me a huge result, a way too bigger hexagon than i want (in the sense that the are contained is almost the entire globe :( ), can anyone englighten me with why this happens and how could i fix it?

all code here

and here as you can see, for the input -71.24 43.06 I'm getting a vertice with coordinates 2 83, which is huge

enter image description here

Upvotes: 0

Views: 576

Answers (1)

dakaj
dakaj

Reputation: 11

I needed that as well on a flutter project, after some research I found out turf.js destination method

By using it, you can get the 6 points of the hexagon around a center point, based on a certain radius:

Point center = Point(coordinates: Position(latitude, longitude)); // Your center point

Point p1 = destination(center, radius, 0, Unit.meters); // top
Point p2 = destination(center, radius, 60, Unit.meters); // top left
Point p3 = destination(center, radius, 120, Unit.meters);  // bottom left
Point p4 = destination(center, radius, 180, Unit.meters); // bottom
Point p5 = destination(center, radius, 240, Unit.meters); // bottom right
Point p6 = destination(center, radius, 300, Unit.meters); // top right

Not sure about this, but Turf seems to be porting to Java as well here

Upvotes: 0

Related Questions