ocmath_d_polygon_area

 

Contents

Description

This function is used to calculate the signed area of a planar non-self-intersecting polygon. If the vertices of the polygon are (x_1, y_1), (x_2, y_2), ..., (x_n, y_n), the area is:

Area= \frac{1}{2} \left ( \begin{vmatrix} x_1 & x_2 \\ y_1 & y_2 \end{vmatrix} + \begin{vmatrix} x_2 & x_3 \\ y_2 & y_3 \end{vmatrix} +...+ \begin{vmatrix} x_n & x_1 \\ y_n & y_1 \end{vmatrix} \right )

  = \frac{1}{2} \left ( x_1y_2-x_2y_1+x_2y_3-x_3y_2+...+x_{n-1}y_n-x_ny_{n-1}+x_ny_1-x_1y_n \right )

For the area of a convex polygon, if the points are arranged anticlockwise, the area will be positive, and if clockwise, will be negative.

Data types supported:

double: ocmath_d_polygon_area

float: ocmath_f_polygon_area

POINT: ocmath_l_polygon_area

Syntax

double ocmath_d_polygon_area(double* pX, double* pY, uint nSize)

Parameters

pX
[input] buffer containing X data of polygon vertexes
pY
[input] buffer containing Y data of polygon vertexes
nSize
[input] size of pX, pY

Return

Polygon area.

Examples

EX1

//For this example to run, make sure a worksheet is active in current project
void ocmath_d_polygon_area_ex1()
{
        Worksheet wks = Project.ActiveLayer();
        wks.SetSize(-1,2);
        DataRange dr;
        dr.Add("X", wks, 0, 0, -1, 0);
        dr.Add("Y", wks, 0, 1, -1, 1);
        
        vector vxData, vyData;
        DWORD dwPlotID;
    if(dr.GetData(DRR_GET_MISSING | DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vyData, &vxData) < 0)
    {
                printf("get data failed!");
                return;
    }
    
        uint nSize = vxData.GetSize();
        double  area = ocmath_d_polygon_area(vxData, vyData, nSize);
    out_double("area=", area);
}

Remark

See Also

ocmath_f_polygon_area, ocmath_l_polygon_area

header to Include

origin.h

Reference