| 12
 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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 
 | 
 round.id <- function (dat, r = 20){
 gx <- dat$gx
 gy <- dat$gy
 id.list <- list()    for (i in 1:nrow(dat)){
 x <- gx[i]
 y <- gy[i]
 dat.sub <- dat[(gx < x + r) &
 (gx > x - r) &
 (gy < y + r) &
 (gy > y - r), ]
 if(nrow(dat.sub) > 1){
 sp <- c()
 for(j in 1:nrow(dat.sub)){
 mat <- data.frame(c(x, dat.sub$gx[j]),
 c(y, dat.sub$gy[j]))
 sp[j] <- (dist(mat) <= r)
 }
 id.include <- dat.sub$ID[sp]
 } else {
 id.include <- 0
 }
 id.list[[i]] <- id.include
 }
 return(id.list)
 }
 
 
 
 Ringring.id <- function (dat, r = c(20, 25)){
 r1 <- max(r)
 r2 <- min(r)
 gx <- dat$gx
 gy <- dat$gy
 id.list <- list()
 
 for (i in 1:nrow(dat)){
 x <- gx[i]
 y <- gy[i]
 dat.sub <- dat[(gx < x + r1) &
 (gx > x - r1) &
 (gy < y + r1) &
 (gy > y - r1), ]
 
 if(nrow(dat.sub) > 1){
 sp <- c()
 for(j in 1:nrow(dat.sub)){
 mat <- data.frame(c(x, dat.sub$gx[j]),
 c(y, dat.sub$gy[j]))
 sp[j] <- (dist(mat) <= r1 & dist(mat) >= r2)
 }
 id.include <- dat.sub$ID[sp]
 } else {
 id.include <- 0
 }
 id.list[[i]] <- id.include
 }
 return(id.list)
 }
 
 ID <- 1:300
 gx <- runif(300, 0, 100)
 gy <- runif(300, 0, 100)
 dat <- data.frame(ID, gx, gy)
 res.round <- round.id(dat, r = 25)
 par(mfrow = c(1, 2))
 
 plot(gy ~ gx, data = dat, col = "gray" )
 vt = seq(-pi,pi,by=0.002);
 x = 25 * sin(vt) + gx[10];
 y = 25 * cos(vt) + gy[10];
 
 lines(y ~ x);
 
 points(gx[10] , gy[10] , pch = 19, col = 2)
 round10 <- res.round[[10]]
 points(gx[round10], gy[round10], col = "green")
 
 
 
 res.ring <- ring.id(dat, c(15, 25))
 plot(gy ~ gx, data = dat, col = "gray" )
 vt = seq(-pi,pi,by=0.002);
 x1 = 25 * sin(vt) + gx[10];
 y1 = 25 * cos(vt) + gy[10];
 
 lines(y1 ~ x1);
 x2 = 15 * sin(vt) + gx[10];
 y2 = 15 * cos(vt) + gy[10];
 
 lines(y2 ~ x2);
 points(gx[10] , gy[10] , pch = 19, col = 2)
 ring10 <- res.ring[[10]]
 
 points(gx[ring10], gy[ring10], col = "blue")
 
 |