What is a good algorithm for calculating the area of ​​a quadrilateral?

I see a good question here for general polygons here . Are there simpler or more efficient algorithms specific to quadrangles?

+3
source share
4 answers

For a (convex) quadrangle, it is often faster to simply split the quadrant into two triangles and calculate the area of ​​two triangles.

If the quadruno is not guaranteed to be convex, a closed polygonal approach is still my advantage, as it is usually faster than checks to figure out how to correctly split the quad.


Edit Comment:

, . , , ( ) , , .

+11

. , .

:

, , ( " " Reed Copsey), . , , , , () , . , , - , , , .

, , , . . , , . , , ( ) . , , ( ) . , , .

, . ; , 0, y0, x1, y1, x2, y2, x3 y3. :

area = 0.5 * abs( x0 * y1 - x1 * y0 + x1 * y2 - x2 * y1 + 
  x2 * y3 - x3 * y2 + x3 * y0 - x0 * y3 )

:

area = 0.5 * abs( x0 * (y1 - y3) + x1 * (y2 - y0) + x2 * (y3 + y1) + 
  x3 * (y0 - y2) )

( * +) 12 . , - :

x2_line = x2 - x0
y2_line = y2 - y0
area = 0.5 * abs( (x1 - x0) * y2_line + (y1 - y0) * x2_line + 
  x2_line * (y3 - y0) + y2_line * (x3 - x0) )

:

x2_line = x2 - x0
y2_line = y2 - y0
area = 0.5 * abs( y2_line * (x1 - x0 + x3 - x0) + x2_line * (y1 - y0 + y3 - y0) )

12 . .

, , , , , , Closed-Polygon , , , .

, , , , , , , -.

+6

The mathworld page lists several formulas.

0
source

Divide the quadrangle into two triangles and calculate the area of ​​both.

Once you have two triangles, Heron Formula works well in a computer program.

For a triangle with sides a, b, and c, the area is

double area = Math.Sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)/16);

This method works with any quadrangle, be it a rectangle, square, rhombus or trapezoid.

0
source

Source: https://habr.com/ru/post/1716015/


All Articles