## Construct points for a grid shaped like a bowl with a hole
np <- 16 # Number of points on each ring
nr <- 12 # Number of rings
theta <- seq(0, 2*pi, len=np+1)[seq(np)]
r <- sqrt(seq(0.01, 8, len=nr))
x <- rep(r, each=length(theta)) * rep(sin(theta), times=length(r))
y <- rep(r, each=length(theta)) * rep(cos(theta), times=length(r))
nn <- length(x)
## Assemble the points into a grid
tri <- matrix(0, 2 * np * (nr - 1), 3)
for(i in seq(nrow(tri))) {
st.node <- ceiling(i / 2)
if(i %% 2) {
tri[i,] <- c(st.node, st.node + np + 1, st.node + 1)
} else {
tri[i,] <- c(st.node, st.node + np, st.node + np + 1)
}
if(!(i %% (2 *np)))
tri[i,3] <- st.node + 1 ## Next layer
if(!((i + 1) %% (2 * np))) {
tri[i,2] <- st.node + 1
tri[i,3] <- st.node - np + 1
}
}
ne <- nrow(tri)
grid <- list(nodes=list(x=x, y=y, lat=y, lon=x, n=nn),
elems=list(tri=tri, n=ne))
## Plot the grid
att.plot(grid, -seq(ne), col=bathy.colors, units='m')Run the code above in your browser using DataLab