# Priklad 13

n <- 100

d <- 10

par (mfrow = c(1,1), mar = c (4,4,4,1))
plot (c(0, d), c(0, d), type = "n", xlab = "bob x", ylab = "bod y")

# Generovani souradnic dvou rezu na tyci delky d
X <- runif (n, 0, d)
Y <- runif (n, 0, d)

V <- data.frame (cbind (X, Y))
V$ok <- ( (V$X <= V$Y) & (V$Y > d/2) & (V$X < d/2) & (V$Y < V$X + d/2) ) | ( (V$X > V$Y) & (V$X > d/2) & (V$Y < d/2) & (V$Y > V$X - d/2) )
V$color <- ifelse (V$ok, "#00cc00", "#ff0000")
V$symbol <- ifelse (V$ok, 1, 4)

points (V$X, V$Y, col = V$color, pch = V$symbol, lwd = 2)
nA <- sum (V$ok)
fA <- nA / n
title (main = paste (nA, "/", n, "=", fA))

