# le coordinate dei due pesci, mettendo di fila le coppie x,y pesce1 <- c( 0.0,-0.40, 0.0,-0.35, 0.2,-0.15, 0.2,0.05, 0.0,0.20, 0.0,0.30, 1.0,0.95, 2.5,1.50, 4.0,1.80, 5.0,1.90, 6.0,1.75, 7.0,1.40, 8.0,1.05, 8.8,0.70, 9.4,1.00, 9.5,1.30, 9.4,1.90, 9.0,2.00, 8.0,1.05, 8.8,0.70, 10.0,0.05, 10.0,-0.25, 11.2,-0.70, 11.3,-0.30, 11.3,0.00, 11.2,0.40, 10.0,0.05, 10.0,-0.25, 9.0,-0.60, 8.0,-1.00, 8.5,-2.00, 9.0,-2.15, 9.6,-2.00, 9.8,-1.50, 9.0,-0.60, 8.0,-1.00, 6.6,-1.70, 5.0,-2.20, 4.0,-2.25, 3.0,-2.20, 2.0,-2.00, 1.4,-1.60, 0.6,-0.80, 0.0,-0.40) pesce2 <- c( 0.0,-0.40, 0.0,-0.35, 0.1,-0.15, 0.1,0.05, 0.0,0.20, 0.0,0.30, 0.5,0.95, 1.25,1.50, 2.0,1.80, 2.5,1.90, 3.0,1.75, 3.5,1.40, 4.0,1.05, 4.4,0.70, 4.7,1.00, 4.75,1.30, 4.7,1.90, 4.5,2.00, 4.0,1.05, 4.4,0.70, 5.0,0.05, 5.0,-0.25, 5.6,-0.70, 5.65,-0.30, 5.64,0.00, 5.6,0.40, 5.0,0.05, 5.0,-0.25, 4.5,-0.60, 4.0,-1.00, 4.25,-2.00, 4.5,-2.15, 4.8,-2.00, 4.9,-1.50, 4.5,-0.60, 4.0,-1.00, 3.3,-1.70, 2.5,-2.20, 2.0,-2.25, 1.5,-2.20, 1.0,-2.00, 0.7,-1.60, 0.3,-0.80, 0.0,-0.40) # quanti sono i punti n <- length(pesce1)/2; n ## da A a B # trasformo la sequenza in una matrice, a due colonne T <- matrix(pesce1,nrow=n,ncol=2,byrow=TRUE) dev.new() plot(c(0,12),c(-6,6),type="n",xlab="",ylab="",asp=1) # La griglia A <- seq(0,12,0.1) B <- seq(-3,3,0.1) A1 <- seq(0,12,1) B1 <- seq(-3,3,1) for(x in A) for (y in B1) points(x,y,pch=".") for(x in A1) for (y in B) points(x,y,pch=".") # la poligonale che raffigura il pesce A lines(T[,1],T[,2],lwd=2) # l'occhio cer <- function(x,y,r) {n <- 50; h <- 2*pi/n; i <- (1:n)*h; lines(cos(i)*r+x,sin(i)*r+y,lwd=2)} cer(1.1,0.5,1/7) # dev.new() # in una nuova finestra il pesce B plot(c(-1,7),c(-4,4),type="n", xlab="",ylab="",asp=1) A <- seq(0,6,0.1) B <- seq(-3,3,0.1) A1 <- seq(0,6,1) B1 <- seq(-3,3,1) fx <- function(x,y) x*0.5 fy <- function(x,y) y for(x in A) for (y in B1) {y1 <- fy(x,y); x1 <- 2*fx(x,y); points(x1,y1,pch=".") } for(x in A1) for (y in B) {y1 <- fy(x,y); x1 <- 2*fx(x,y); points(x1,y1,pch=".") } lines(fx(T[,1],T[,2]),fy(T[,1],T[,2]),lwd=2) cer(fx(1.1,0.5),fy(1.1,0.5),1/7) # ## da A a D dev.new() plot(c(0,12),c(-6,6),type="n",xlab="",ylab="",asp=1) A <- seq(0,12,0.1) B <- seq(-3,3,0.1) A1 <- seq(0,12,1) B1 <- seq(-3,3,1) for(x in A) for (y in B1) points(x,y,pch=".") for(x in A1) for (y in B) points(x,y,pch=".") lines(T[,1],T[,2],lwd=2) cer(1.1,0.5,1/7) # dev.new() plot(c(0,14),c(-7,7),type="n", xlab="",ylab="",asp=1) A <- seq(0,12,0.1) B <- seq(-3,3,0.1) A1 <- seq(0,12,1) B1 <- seq(-3,3,1) fx <- function(x,y) x-(abs(y)/10)^1.15 fy <- function(x,y) abs((1+x^1.4/10)*y)^1.001*sign(y) for(x in A) for (y in B1) {y1 <- fy(x,y); x1 <- fx(x,y); points(x1,y1,pch=".") } for(x in A1) for (y in B) {y1 <- fy(x,y); x1 <- fx(x,y); points(x1,y1,pch=".") } lines(fx(T[,1],T[,2]),fy(T[,1],T[,2]),lwd=2) cer(fx(1.1,0.5),fy(1.1,0.5),1/7) # n <- length(pesce2)/2; n ## da B a C dev.new() T <- matrix(pesce2,nrow=n,ncol=2,byrow=TRUE) plot(c(-1,7),c(-4,4),type="n",xlab="",ylab="",asp=1) A <- seq(0,6,0.1) B <- seq(-3,3,0.1) A1 <- seq(0,6,1) B1 <- seq(-3,3,1) for(x in A) for (y in B1) points(x,y,pch=".") for(x in A1) for (y in B) points(x,y,pch=".") lines(T[,1],T[,2],lwd=2) cer(0.55,0.5,1/7) # dev.new() plot(c(-1,7),c(-4,4),type="n", xlab="",ylab="",asp=1) fx <- function(x,y) x+y*0.4 fy <- function(x,y) y for(x in A) for (y in B1) {y1 <- fy(x,y); x1 <- fx(x,y); points(x1,y1,pch=".") } for(x in A1) for (y in B) {y1 <- fy(x,y); x1 <- fx(x,y); points(x1,y1,pch=".") } lines(fx(T[,1],T[,2]),fy(T[,1],T[,2]),lwd=2) cer(fx(0.55,0.5),fy(0.55,0.5),1/7)