PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwtriangle_area()

double lwtriangle_area ( const LWTRIANGLE triangle)

Find the area of the outer ring.

Definition at line 185 of file lwtriangle.c.

References area(), getPoint2d_p(), POINTARRAY::npoints, LWTRIANGLE::points, POINT2D::x, and POINT2D::y.

Referenced by lwgeom_area().

186 {
187  double area=0.0;
188  uint32_t i;
189  POINT2D p1;
190  POINT2D p2;
191 
192  if (! triangle->points->npoints) return area; /* empty triangle */
193 
194  for (i=0; i < triangle->points->npoints-1; i++)
195  {
196  getPoint2d_p(triangle->points, i, &p1);
197  getPoint2d_p(triangle->points, i+1, &p2);
198  area += ( p1.x * p2.y ) - ( p1.y * p2.x );
199  }
200 
201  area /= 2.0;
202 
203  return fabs(area);
204 }
POINTARRAY * points
Definition: liblwgeom.h:435
Datum area(PG_FUNCTION_ARGS)
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
double y
Definition: liblwgeom.h:330
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:338
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: