library(rgl)
plotEdges <- function(vertices, edges, ...){
for(i in 1L:nrow(edges)){
edge <- edges[i, ]
lines3d(rbind(vertices[edge[1L], ], vertices[edge[2L], ]), ...)
}
invisible(NULL)
}
phi <- (1+sqrt(5))/2
a <- 1/sqrt(3)
b <- a/phi
c <- a*phi
vertices <-
rbind(
c( a, a, a),
c( a, a, -a),
c( a, -a, a),
c(-a, -a, a),
c(-a, a, -a),
c(-a, a, a),
c( 0, b, -c),
c( 0, -b, -c),
c( 0, -b, c),
c( c, 0, -b),
c(-c, 0, -b),
c(-c, 0, b),
c( b, c, 0),
c( b, -c, 0),
c(-b, -c, 0),
c(-b, c, 0),
c( 0, b, c),
c( a, -a, -a),
c( c, 0, b),
c(-a, -a, -a)
)
vs1 <- vertices[c(17, 14, 2, 11), ]
vs2 <- vertices[c(18, 1, 4, 5), ]
vs3 <- vertices[c(19, 6, 15, 7), ]
vs4 <- vertices[c(3, 13, 12, 8), ]
vs5 <- vertices[c(20, 16, 10, 9), ]
faces <- rbind(
c(1, 2, 3),
c(3, 2, 4),
c(4, 2, 1),
c(1, 3, 4)
)
lfaces <- lapply(1:nrow(faces), function(i) as.integer(faces[i, ]-1))
lfacescopy = lapply(lfaces, identity)
mesh1 <- list(
vertices = t(vs1),
faces = lfaces
)
mesh2 <- list(
vertices = t(vs2)/1.05,
faces = lfaces
)
mesh3 <- list(
vertices = t(vs3)/1.1,
faces = lfacescopy
)
mesh4 <- list(
vertices = t(vs4)/1.15,
faces = lfaces
)
mesh5 <- list(
vertices = t(vs5),
faces = lfaces
)
ii <- RCGAL:::Intersection(
list(mesh1, mesh2, mesh3),
TRUE, FALSE, FALSE
)
# vv = ii$vertices
# ff = lapply(ii$faces, function(x) x-1L)
# mm = list(vertices = vv, faces = ff)
# iii <- RCGAL:::Intersection(
# list(
# mesh4,
# mesh3
# ),
# FALSE, FALSE, FALSE
# )
mm = list(vertices = structure(c(-0.577350269189626, 0, 0, 0, -0.577350269189626,
0, 0.136293910356554, -0.577350269189626, -0.136293910356554,
-0.35682208977309, 0.220528179416536, -0.441056358833072, -0.577350269189626,
0.136293910356554, -0.136293910356554, 0.220528179416536, 0.441056358833072,
0.35682208977309, 0.136293910356554, 0.136293910356554, 0.577350269189626,
0, 0, 0.577350269189626, 0.441056358833072, -0.35682208977309,
-0.220528179416536, 0.467086179481358, -0.178411044886545, -0.288675134594813,
-0.178411044886545, 0.288675134594813, -0.467086179481358, 0.288675134594813,
0.467086179481358, 0.178411044886545), .Dim = c(3L, 12L)), faces = list(
c(1L, 0L, 4L, 3L, 2L), c(4L, 0L, 7L, 6L, 5L), c(7L, 0L, 1L
), c(7L, 1L, 2L, 8L, 6L), c(2L, 3L, 10L, 9L, 8L), c(3L, 4L,
5L, 11L, 10L), c(5L, 6L, 8L, 9L, 11L), 9:11))
iiii <- RCGAL:::Intersection(
list(
list(vertices = structure(c(-0.35682208977309, -0.220528179416536,
0, -0.258198889747161, -0.258198889747161, 0.258198889747161,
-4.45671112231067e-17, -0.35682208977309, 0.220528179416536,
-3.60555503696918e-17, -0.35682208977309, -0.220528179416536,
-0.178411044886545, -0.288675134594813, -0.467086179481358, -0.178411044886545,
-0.288675134594813, -0.467086179481358, -0.220528179416536, 2.11072868313427e-16,
-0.35682208977309, -0.35682208977309, 0.220528179416536, -1.26643720988056e-16,
-0.288675134594813, 0.467086179481358, 0.178411044886545, -0.288675134594813,
0.467086179481358, 0.178411044886545, -0.220528179416536, 0,
0.35682208977309, 0.220528179416536, 0, 0.35682208977309, 0.467086179481358,
-0.178411044886545, 0.288675134594813, 0.467086179481358, -0.178411044886545,
0.288675134594813, 0.35682208977309, -0.220528179416536, 0, 0.220528179416536,
-1.04360165376503e-16, -0.35682208977309, 0.258198889747161,
0.258198889747161, -0.258198889747161, 0, 0.35682208977309, -0.220528179416536,
0.35682208977309, 0.220528179416536, 8.91342224462135e-17, 2.16333302218151e-16,
0.35682208977309, 0.220528179416536), .Dim = c(3L, 20L)), faces = list(
c(1L, 0L, 5L, 4L, 3L, 2L), c(5L, 0L, 7L, 6L), c(7L, 0L, 1L,
10L, 9L, 8L), c(10L, 1L, 2L, 13L, 12L, 11L), c(13L, 2L, 3L,
14L), c(3L, 4L, 15L, 14L), c(5L, 6L, 17L, 16L, 15L, 4L),
c(6L, 7L, 8L, 17L), c(17L, 8L, 9L, 19L, 18L, 16L), c(19L,
9L, 10L, 11L), c(18L, 19L, 11L, 12L), c(14L, 15L, 16L, 18L,
12L, 13L))),
mesh1),
# list(vertices = structure(c(-0.493116000129644, 0, 0.35682208977309,
# 0.493116000129644, 0, 0.35682208977309, 0.441056358833072, -0.35682208977309,
# 0.220528179416536, 0.288675134594813, -0.467086179481358, 0.178411044886545,
# -0.467086179481358, -0.178411044886545, 0.288675134594813, -0.178411044886545,
# -0.288675134594813, -0.467086179481358, -0.136293910356554, -0.136293910356554,
# -0.577350269189626, -0.441056358833072, 0.35682208977309, 0.220528179416536,
# -0.288675134594813, 0.467086179481358, 0.178411044886545, 0.467086179481358,
# 0.178411044886545, 0.288675134594813, 0.178411044886545, 0.288675134594813,
# -0.467086179481358, 0.136293910356554, 0.136293910356554, -0.577350269189626
# ), .Dim = c(3L, 12L)), faces = list(c(1L, 0L, 4L, 3L, 2L), c(4L,
# 0L, 7L, 6L, 5L), c(7L, 0L, 1L, 9L, 8L), c(2L, 11L, 10L, 9L, 1L
# ), c(3L, 5L, 6L, 11L, 2L), 3:5, c(6L, 7L, 8L, 10L, 11L), c(10L,
# 8L, 9L)))
FALSE, TRUE, FALSE
)
dput(list(vertices=iiii$vertices, faces = lapply(iiii$faces, function(x) x-1L)))
tmesh <- tmesh3d(
vertices = ii$vertices,
indices = do.call(cbind, ii$faces),
homogeneous = FALSE
)
t2 <- tmesh3d(
vertices = mesh3$vertices,
indices = t(faces),
homogeneous = FALSE
)
open3d()
#shade3d(t1, color = "cyan", alpha = 0.2)
shade3d(t2, color = "palegreen", alpha = 0.4)
shade3d(tmesh, color="red")
plotEdges(t(ii$vertices), t(ii$edges0))
wire3d(tmesh, lwd=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.