Description Usage Arguments Value Examples
Method 'circular' (default) used the most triangles so far by going round in the circle and connecting the next three vertices. 'fix' uses vertex id 1 and creates triangles to all other points round. 'planar' always flips the triangles.
1 |
n |
number of vertices. |
method |
Method how to organize the triangles 'circular', 'planar', 'fix' and 'center'. |
center |
The center vertex ID for the central point (method 'center' only; default NA). |
A vector of indices for the polygon vertices.
1 2 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 | par(mfrow=c(2,2))
for (m in c("plan", "fix", "center", "")) {
faces <- sample(12:20, 1)
vertices <- sapply(seq(0, 2*pi*(faces-1)/faces, length.out=faces),
function(x){c(sin(x), cos(x))})
tri = triClose(faces, method=m)
if (m == "center") {
tri[is.na(tri)] = faces + 1
vertices = cbind(vertices, c(mean(vertices[1,]), mean(vertices[2, ])))
}
plot(vertices[1,1:faces], vertices[2,1:faces], type="b")
text(x=1.05*vertices[1,], y=1.05*vertices[2,], labels=1:faces, adj=0.5)
for (i in seq(1, length(tri), 3))
polygon(vertices[1,tri[i:(i+2)]], vertices[2,tri[i:(i+2)]],
col=rgb(runif(1), runif(1), runif(1)))
}
par(mfrow=c(2,2))
for (faces in c(6, 12, 13, 25)) {
vertices <- sapply(seq(0, 2*pi*(faces-1)/faces, length.out=faces),
function(x){c(sin(x), cos(x))})
tri = triClose(faces, method=m)
plot(vertices[1,], vertices[2,], type="b")
text(x=1.05*vertices[1,], y=1.05*vertices[2,], labels=1:faces, adj=0.5)
for (i in seq(1, length(tri), 3))
polygon(vertices[1,tri[i:(i+2)]], vertices[2,tri[i:(i+2)]],
col=rgb(runif(1), runif(1), runif(1)))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.