hypertidy / textures

simple texture plot
GNU General Public License v3.0
12 stars 0 forks source link

expand mesh coercions quad-segment, etc. #12

Open mdsumner opened 2 years ago

mdsumner commented 2 years ago
quad2segment <- function(mesh) {
  ib <- mesh$ib
  allseg <- cbind(ib[1:2, ], ib[2:3, ], ib[3:4, ], ib[c(4, 1), ])
  dup <- duplicated(pmax(paste(allseg[1, ], allseg[2, ], sep = "-"), 
                         paste(allseg[2, ], allseg[1, ], sep = "-")))
  rgl::mesh3d(vertices = mesh$vb, segments = allseg[, !dup])
}

could have a kind of nascent quadmesh that started with just these segments, but would need to record the dim too

mdsumner commented 2 years ago

also see hypertidy/structuredmesh - but I think the cpp11 port in quad covers that now

[llbox](https://github.com/mdsumner/llbox also has a bit of raw generation with R

see more in this tweet https://twitter.com/mdsumner/status/1542765130919817217

mdsumner commented 9 months ago

here's segments from dimension (I need this in bigcurve)

quad2segment <- function(ib) {

  allseg <- cbind(ib[1:2, ], ib[2:3, ], ib[3:4, ], ib[c(4, 1), ])
  dup <- duplicated(pmax(paste(allseg[1, ], allseg[2, ], sep = "-"), 
                         paste(allseg[2, ], allseg[1, ], sep = "-")))
  allseg[, !dup]
}

library(quad)
dm <- c(3, 2)
ib <- matrix(quad_index(dm, ydown = TRUE), nrow = 4L) + 1
vb <- matrix(quad_vert(dm, ydown = TRUE), nrow = 2L)
plot(t(vb), pch = ".")
polygon(t(vb[, rbind(ib, ib[1, ], NA)]))
is <- quad2segment(ib)

segments(x0 = vb[1, is[1, ]], y0 = vb[2, is[1, ]], x1 = vb[1, is[2, ]], y1 = vb[2, is[2, ]], lwd = 1:17)

image