Home > Enterprise >  Formula for Quadrilateral area
Formula for Quadrilateral area

Time:09-22

I do not find formula for determination of area of Quadrilateral with four vertices (points). Who is strong in math and can help with Java formula for it. Thanks very much. I know only that 'convex quadrilaterals are divided into two triangles by any of their diagonals'.

CodePudding user response:

Having vertices coordinates we can calculate are of any polygon using shoelace formula

Java code from here

public static double polygonArea(double X[], double Y[], int n)
{
    // Initialize area
    double area = 0.0;
 
    // Calculate value of shoelace formula
    int j = n - 1;
    for (int i = 0; i < n; i  )
    {
        area  = (X[j]   X[i]) * (Y[j] - Y[i]);
         
        // j is previous vertex to i
        j = i;
    }
 
    // Return absolute value
    return Math.abs(area / 2.0);
}

For specific case of quadrilateral we can write result without loops

Area = 0.5 * ((x[0]*y[1] x[1]*y[2] x[2]*y[3] x[3]*y[0]) - 
              (x[1]*y[0] x[2]*y[1] x[3]*y[2] x[0]*y[3]))
  • Related