area.polygon {pcds} | R Documentation |
The area of a polygon in R^2
Description
Returns the area of the polygon, h
,
in the real plane R^{2}
; the vertices of the polygon h
must be provided in clockwise or counter-clockwise order,
otherwise the function does not yield
the area of the polygon. Also, the polygon could be convex or non-convex.
See (Weisstein (2019)).
Usage
area.polygon(h)
Arguments
h |
A |
Value
area of the polygon h
Author(s)
Elvan Ceyhan
References
Weisstein EW (2019). “Polygon Area.” From MathWorld — A Wolfram Web Resource, http://mathworld.wolfram.com/PolygonArea.html.
Examples
A<-c(0,0); B<-c(1,0); C<-c(0.5,.8);
Tr<-rbind(A,B,C);
area.polygon(Tr)
A<-c(0,0); B<-c(1,0); C<-c(.7,.6); D<-c(0.3,.8);
h1<-rbind(A,B,C,D);
#try also h1<-rbind(A,B,D,C) or h1<-rbind(A,C,B,D) or h1<-rbind(A,D,C,B);
area.polygon(h1)
Xlim<-range(h1[,1])
Ylim<-range(h1[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
plot(h1,xlab="",ylab="",main="A Convex Polygon with Four Vertices",
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(h1)
xc<-rbind(A,B,C,D)[,1]+c(-.03,.03,.02,-.01)
yc<-rbind(A,B,C,D)[,2]+c(.02,.02,.02,.03)
txt.str<-c("A","B","C","D")
text(xc,yc,txt.str)
#when the triangle is degenerate, it gives zero area
B<-A+2*(C-A);
T2<-rbind(A,B,C)
area.polygon(T2)
[Package pcds version 0.1.8 Index]