tri_area: Area of triangles

View source: R/triangles.R

tri_areaR Documentation

Area of triangles

Description

Input is x,y matrix in triplets, with 3 rows per triangle vertex.

Usage

tri_area(x)

Arguments

x

matrix of triangle coordinates

Value

numeric, area of triangles

Examples

pts <- structure(c(5L, 3L, 1L, 4L, 4L, 8L, 6L, 9L), .Dim = c(4L, 2L))
tri <- c(2, 1, 3, 2, 4, 1)
(a <- tri_area(pts[tri, ]))
plot(pts)
polygon(pts[head(as.vector(rbind(matrix(tri, nrow = 3), NA)), -1), ])
text(tapply(pts[tri,1], rep(1:2, each = 3), mean),
     tapply(pts[tri,2], rep(1:2, each = 3), mean), labels = sprintf("area: %0.1f", a))

silicate documentation built on Jan. 7, 2023, 1:15 a.m.