envelopeArea_and_Perimeter: Calculate the area and perimeter of the envelope

Description Usage Arguments Details Value Author(s) References Examples

Description

Calculate the area and perimeter of the envelope

Usage

1

Arguments

segments

The tangent points output by the generateEnvelope function

centers

a numeric matrix with each row containing the coordinates for a point with the x and y coordinates as the two columns.

r

a numeric vector containing the radii for each point

Details

Calculations are done in the units of the graph

Value

a numeric vector. The area is the first value and the perimeter is the second value

Author(s)

Elliot Noma

References

http://en.wikipedia.org/wiki/Belt_problem

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
############################################################
# plot 

plotCircles <- function(center, r, color="red", ...) 
{
	a <- createCircle(center, r, ...)
	grid.polygon(x = a[,1], y = a[,2], gp=gpar(col=color, lwd=2))
	
	a
} 

ncircles <- sample(3:7,1)
centers <- matrix(runif(2*ncircles, min=.2, max=.8), byrow=TRUE, ncol=2)
r <- runif(ncircles,min=.10, max=.20)

envelope <- generateEnvelope(centers, r)
print(envelope$tangent_Points)

require(grid)
grid.newpage()
colors <- rainbow(ncircles * 3 + 3)
for (i in 1:ncircles) circles<- plotCircles(centers[i,], r[i], color=colors[i])
grid.text(1:ncircles, centers[,1], centers[,2])

# plot the envelope containing the circles

envelopeXY <- envelope$envelopeXY
segments <- envelope$tangent_Points

grid.lines(envelopeXY[,1], envelopeXY[,2], gp=gpar(col="orange", lwd=5), default.units="npc")
grid.points(segments[,"x"], segments[,"y"], pch=16, gp=gpar(col="red"), default.units="npc")

# calculate the area and perimeter of the envelope

envelopeStats <- envelopeArea_and_Perimeter(segments, centers, r)

cat("envelope area = ", envelopeStats["area"], " perimeter = ", envelopeStats["perimeter"],"\n")	
cat("circle radii = ", r, "\n")
cat("circle area = ", pi * r^2, " = ", sum(pi * r^2), "\ncircle perimenter = ",  2 * pi * r, " = ",  2 * pi * sum(r), "\n")

Example output

          segment circle adjacent_circle         x          y      theta
minPoint1      21      3               5 0.9117556 0.22495166 -0.6522556
minPoint2      21      5               3 0.8585389 0.78225655  0.8999337
minPoint2       8      5               1 0.7020157 0.86366911  1.3304856
minPoint1       8      1               5 0.5303472 0.76620837  1.8049326
minPoint1       9      1               6 0.4971983 0.74010027  1.9334042
minPoint2       9      6               1 0.1919885 0.41436460  3.2535130
minPoint2      24      6               3 0.2631710 0.15443629  3.8745466
minPoint1      24      3               6 0.6799322 0.03309656  4.8898986
minPoint1      21      3               5 0.9117556 0.22495166  5.6309297
Loading required package: grid
envelope area =  0.4635634  perimeter =  2.566461 
circle radii =  0.140453 0.1341208 0.1818203 0.1138959 0.1051068 0.1581193 
circle area =  0.0619743 0.0565122 0.1038568 0.04075362 0.03470658 0.07854517  =  0.3763486 
circle perimenter =  0.8824919 0.8427059 1.142411 0.7156291 0.6604058 0.9934927  =  5.237136 

PlotRegionHighlighter documentation built on May 2, 2019, 9:34 a.m.