# Calculate meter offset around decimal degree position

I have a position given in decimal degrees (x.xxxxxxxx and y.yyyyyyyy). I need to draw a rectangle around it. The center of the rectangle matches the position. The dimensions of the rectangle is given in meters and it has a rotation ranging from 0-360 degrees.

Question How can I calculate the four corners of the rectangle and return the result as four decimal degree values? Like `arrayOf<LatLon> getRectangle(LatLon position, int rectWidthCm, int rectLengthCm, double rectRotation)`.

Example

1. I have a position given in LatLon format with two double values: latitude and longitude. We will assume this location is precice.
2. Then I get the task to draw a rectangle based on this position in a Google Maps chart. The rectangle can have any dimentions but let's use these in this example: Width = 0.9 meter and Length = 1.2 meters. Any heading may also be given so lets use this heading: 45. 0 Is north and going clockwise round (east = 90, south = 180 and west = 270). When the rectangle is pointing north it has the length in the north/south direction. Finally, the rectangle center should be equal to the given position.

Note: The project setup is an Android application with Kotlin support and a google maps chart. I am interested in a modern approach to this problem. Regarding precision loss it should at most be within centimeters.

• I really doubt that you can get corners precision in centimeters when input is in decimal degrees (WGS 84). Unless you drop Java and switch to COBOL. – Remigijus Pankevičius May 13 at 11:00
• PS. In general, even COBOL or FORTRAN won't help you if you try to solve any practical problem, not theoretical one. It's because you won't get input point coordinates in centimeters precision, so any calculation on a input point with precision of 4 meters can't give an output point with precision less than 4 meters. See gis.stackexchange.com/questions/43617/… – Remigijus Pankevičius May 13 at 11:11
• @RemigijusPankevičius I am not sure we are talking about the same thing here. According to wikipedia (en.wikipedia.org/wiki/Decimal_degrees) it only requires 7 to 8 decimals which should be just fine for a double on a 64 bit system - even 32 bit. – 7heViking May 13 at 11:33
• Yes, that's true, so I'd say it may be possible mathematically to get this precision with double precision floating point. But still it's not clear for me how will you get the input point coordinates of that centimeter precision? – Remigijus Pankevičius May 13 at 12:30
• Ah I see what you mean. What I want to do is not to loose any more precision than centimeters in the calculation of the four corners. So given an input with 8 significant decimals a result should be return with at least 7 significant decimals. If no loss can be achieved it would ofcourse be GREAT :) – 7heViking May 13 at 12:57