Learn R Programming

area (version 0.2.0)

triangle_area: Area of triangles

Description

Calculate triangle area from a matrix of coordinates. Triangles are composed of three coordinates, so the matrix should have this as triplets of rows one after the other.

Usage

triangle_area(x, signed = FALSE)

Value

numeric vector of area

Arguments

x

coordinates x,y triplets matrix where 'nrow(x) = ntriangles*3'

signed

defaults to FALSE and absolute value of area is returned, if TRUE negative means clockwise 'p->q->r' turns right and positive means counter-clockwise 'p->q->r' turns left

Details

If signed = FALSE the absolute value of area is returned, otherwise the sign reflects path orientation. Positive means counter-clockwise orientation.

The algorithm was once documented at 'w w w cs.tufts.edu/comp/163/OrientationTests.pdf'

Examples

Run this code
sum(triangle_area(mm_tri$P[t(mm_tri$T), ]))

Run the code above in your browser using DataLab