C
C
chelkaz2017-05-12 15:51:44
Mathematics
chelkaz, 2017-05-12 15:51:44

How to calculate area by points (Map) in space?

There are diagonal vertices.
Here is an example:
x(A , B) and y(A , B)
1) - 179.306462 , 63.034977
2) - 179.370413 , 63.067053
To calculate and get a rectangle from them, I do the following: Draw in space by coordinates:
from x( A , B) to x(A) y(B) to y(A , B) to y(A) x(B) and connect to x(A , B)
It turns out a rectangle as needed.
But here's the problem, if there are many such rectangles, how can I find out which of them has the largest area?
I wanted like this and I think it's correct for this:
2) 179.306462, 63.067053 3) 179.370413, 63.067053
1) 179.306462, 63.034977 4) 179.370413, 63.034977
Subtract the distance 63.067053 - 63.034977 and multiply by the difference 179.370413 - 179.306462
This will be the number, which is greater, the higher the priority of the rectangle, respectively, but there are still points with a minus in the coordinates and here I got into a stupor ... Here is an example of such a rectangle with minuses:
-169.115964.65.762301, -169.106136.65.762301,
-169.115964.65.758185, -169.106136.65.758185,
Here you can’t subtract as in the first one ... How to universally calculate the priority of the area of ​​rectangles, knowing only two vertices in space on the map .. .

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
chelkaz, 2017-05-12
@chelkaz

Found a library for calculating https://github.com/mjaschen/phpgeo

R
Rsa97, 2017-05-12
@Rsa97

Just one diagonal (two points) gives an infinite number of rectangles, the largest in area of ​​which will be a square with a second diagonal perpendicular to the existing one. The area will be equal to half the square of the diagonal or, through the coordinates of the points:
S \u003d ((x 2 - x 1 ) 2 + (y 2 - y 1 ) 2 ) / 2
If we add the restriction that the sides of the rectangle must be parallel to the coordinate axes, then one rectangle with area
S = |x 2 - x 1 | * |y 2 - y 1 |

S
Sergey Sokolov, 2017-05-12
@sergiks

You can use the Google Maps API computeArea() method - pass an array of 4 points of your rectangle there as the first parameter.
Upd. A little googling, I found a formula for calculating the area:

A = 2*pi*R^2 |sin(lat1)-sin(lat2)| |lon1-lon2|/360
    = (pi/180)R^2 |sin(lat1)-sin(lat2)| |lon1-lon2|

Those. in JavaScript it would be something like this:
// Площадь прямоугольника, заданного двумя параллелями и двумя меридианами
function area( lat1, lat2, lng1, lng2, R) {
  R = R || 6371000; // радиус Земли в метрах
  var k = Math.PI / 180;
  return k * R * R 
    * Math.abs( Math.sin(lat1 * k) - Math.sin(lat2 * k))
    * Math.abs( lng1 - lng2);
}

I got an area in Google using your coordinates , and 205804.64643832657with my JS code 205344.32281511626- probably because of the value of the Earth's radius, which I took from Wiki, and Google found a more accurate one for this latitude.
area( 65.758185, 65.762301, -169.115964, -169.106136) // 205344.32281511626

F
freeExec, 2017-05-15
@freeExec

If you don't like the cons, you can shift it 180 degrees and count from 0 to 360.
Well, different areas can be obtained when the earth is represented as a ball or as an ellipsoid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question