computeArea: Compute area enclosed within an irregular polygon

View source: R/computeArea.r

computeAreaR Documentation

Compute area enclosed within an irregular polygon

Description

Compute area enclosed within an irregular polygon - i.e. defined by curves

Usage

computeArea(x)

Arguments

x

k x 2 or k x 3 matrix containing ordered coordinates forming the boundary of the area. For 3D-cases, the area should be closed to a 2D surface (see details below).

Details

For 3D coordinates, a PCA is computed and only the first two PCs are used to compute the area. This is a projection of the coordinates onto a 2D plane spanned by those PCs.

Value

returns a list containing

area

size of the enclosed area

xpro2D

projected coordinates of x in the 2D plane.

poly

object of class sp as defined by the sp package.

xpro3D

For 3D-cases, this contains the projected coordinates of x rotated back into the original coordinate system

Note

in case custom planes are preferred, the data can first be projected onto such a custom defined plane via points2plane first.

Examples

require(shapes)
require(sf)
myarea <- computeArea(gorf.dat[c(1,6:8,2:5),,1])
myarea$area
plot(myarea$poly)


## 3D example
data(boneData)
myarea3D <- computeArea(boneLM[c(4,2,3,7,5,6,8),,1])
plot(myarea3D$poly)
cent <- colMeans(myarea3D$xpro2D)
text(cent[1],cent[2],labels=paste0("Area=",round(myarea3D$area,digits=2)))

zarquon42b/Morpho documentation built on Jan. 28, 2024, 2:11 p.m.