update version
[gpclib.git] / man / gpc.poly-class.Rd
blob2155dde68f2a396cf9b94e2087fb35789069d0af
1 \name{gpc.poly-class}
2 \docType{class}
3 \alias{gpc.poly-class}
4 \alias{[,gpc.poly-method}
5 \alias{append.poly,gpc.poly,gpc.poly-method}
6 \alias{area.poly,gpc.poly-method}
7 \alias{coerce,matrix,gpc.poly-method}
8 \alias{coerce,data.frame,gpc.poly-method}
9 \alias{coerce,gpc.poly,matrix-method}
10 \alias{coerce,gpc.poly,numeric-method}
11 \alias{coerce,numeric,gpc.poly-method}
12 \alias{get.bbox,gpc.poly-method}
13 \alias{get.pts,gpc.poly-method}
14 \alias{intersect,gpc.poly,gpc.poly-method}
15 \alias{plot,gpc.poly-method}
16 \alias{scale.poly,gpc.poly-method}
17 \alias{setdiff,gpc.poly,gpc.poly-method}
18 \alias{show,gpc.poly-method}
19 \alias{union,gpc.poly,gpc.poly-method}
21 \title{Class "gpc.poly"}
22 \description{
23   A class for representing polygons composed of multiple contours, some
24   of which may be holes.
26 \section{Objects from the Class}{
27   Objects can be created by calls of the form \code{new("gpc.poly",
28     ...)} or by reading in from a file using \code{read.polyfile}.
30 \section{Slots}{
31   \describe{
32     \item{\code{pts}:}{Object of class \code{"list"}.  Actually,
33       \code{pts} is a list of lists with length equal to the number of
34       contours in the \code{"gpc.poly"} object.  Each element of
35       \code{pts} is a list of length 3 with names \code{x}, \code{y},
36       and \code{hole}.  \code{x} and \code{y} are vectors containing the
37       x and y coordinates, respectively, while \code{hole} is a logical
38       indicating whether or not the contour is a hole.}
39   }
41 \section{Methods}{
42   \describe{
43     \item{[}{\code{signature(x = "gpc.poly")}: ... }
44     \item{append.poly}{\code{signature(x = "gpc.poly", y = "gpc.poly")}: ... }
45     \item{area.poly}{\code{signature(object = "gpc.poly")}: ... }
46     \item{coerce}{\code{signature(from = "matrix", to = "gpc.poly")}: ... }
47     \item{coerce}{\code{signature(from = "data.frame", to = "gpc.poly")}: ... }
48     \item{coerce}{\code{signature(from = "gpc.poly", to = "matrix")}: ... }
49     \item{coerce}{\code{signature(from = "gpc.poly", to = "numeric")}: ... }
50     \item{coerce}{\code{signature(from = "numeric", to = "gpc.poly")}: ... }
51     \item{get.bbox}{\code{signature(x = "gpc.poly")}: ... }
52     \item{get.pts}{\code{signature(object = "gpc.poly")}: ... }
53     \item{intersect}{\code{signature(x = "gpc.poly", y = "gpc.poly")}: ... }
54     \item{plot}{\code{signature(x = "gpc.poly")}: The argument
55       \code{poly.args} can be used to pass a list of additional
56       arguments to be passed to the underlying \code{polygon} call.}
57     \item{scale.poly}{\code{signature(x = "gpc.poly")}: ... }
58     \item{setdiff}{\code{signature(x = "gpc.poly", y = "gpc.poly")}: ... }
59     \item{show}{\code{signature(object = "gpc.poly")}: Scale x and y
60       coordinates by amount \code{xscale} and \code{yscale}.  By default
61       \code{xscale} equals \code{yscale}.}
62     \item{union}{\code{signature(x = "gpc.poly", y = "gpc.poly")}: ... }
63   }
65 \author{Roger D. Peng}
67 \note{
68   The class \code{"gpc.poly.nohole"} is identical to
69   \code{"gpc.poly"} except the \code{hole} flag for each contour of a
70   \code{"gpc.poly.nohole"} object is always \code{FALSE}.
73 \examples{
74 ## Make some random polygons
75 set.seed(100)
76 a <- cbind(rnorm(100), rnorm(100))
77 a <- a[chull(a), ]
79 ## Convert `a' from matrix to "gpc.poly"
80 a <- as(a, "gpc.poly")
82 b <- cbind(rnorm(100), rnorm(100))
83 b <- as(b[chull(b), ], "gpc.poly")
85 ## More complex polygons with an intersection
86 p1 <- read.polyfile(system.file("poly-ex/ex-poly1.txt", package = "gpclib"))
87 p2 <- read.polyfile(system.file("poly-ex/ex-poly2.txt", package = "gpclib"))
89 ## Plot both polygons and highlight their intersection in red
90 plot(append.poly(p1, p2))
91 plot(intersect(p1, p2), poly.args = list(col = 2), add = TRUE)
93 ## Highlight the difference p1 \ p2 in green
94 plot(setdiff(p1, p2), poly.args = list(col = 3), add = TRUE)
96 ## Highlight the difference p2 \ p1 in blue
97 plot(setdiff(p2, p1), poly.args = list(col = 4), add = TRUE)
99 ## Plot the union of the two polygons
100 plot(union(p1, p2))
102 ## Take the non-intersect portions and create a new polygon
103 ## combining the two contours
104 p.comb <- append.poly(setdiff(p1, p2), setdiff(p2, p1))
105 plot(p.comb, poly.args = list(col = 2, border = 0))
109 ## Coerce from a matrix
110 x <- 
111 structure(c(0.0934073560027759, 0.192713393476752, 0.410062456627342, 
112 0.470020818875781, 0.41380985426787, 0.271408743927828, 0.100902151283831, 
113 0.0465648854961832, 0.63981588032221, 0.772382048331416,
114 0.753739930955121, 0.637744533947066, 0.455466052934407,
115 0.335327963176065, 0.399539700805524, 
116 0.600460299194476), .Dim = c(8, 2))
117 y <- 
118 structure(c(0.404441360166551, 0.338861901457321, 0.301387925052047, 
119 0.404441360166551, 0.531852879944483, 0.60117973629424, 0.625537820957668, 
120 0.179976985040276, 0.341542002301496, 0.445109321058688,
121 0.610817031070196, 0.596317606444189, 0.459608745684695,
122 0.215189873417722), .Dim = c(7, 2))
124 x1 <- as(x, "gpc.poly")
125 y1 <- as(y, "gpc.poly")
127 plot(append.poly(x1, y1))
128 plot(intersect(x1, y1), poly.args = list(col = 2), add = TRUE)
130 \keyword{classes}