-
Notifications
You must be signed in to change notification settings - Fork 10
Quads vs Triangles
Michael Sumner edited this page May 23, 2020
·
3 revisions
Two-minute explanation of https://twitter.com/mdsumner/status/1264039295947431936/photo/1
Referring to the pic at twitter above:
(the coloured primitives are triangles, anchored to pixel centre at each x,y the wire traverses each pixel boundary - a quad)
The matrix values "are at" the triangle corners (the quad corners use a defensible and simple trick)
Here looking in 2D:
## mesh3d way (with a quad interpretation)
z <- matrix(c(1:6, 6:1), 4)
x <- 1:4
y <- 1:3
library(anglr)
## surface3d way
rr <- raster::raster(list(x = x, y = y, z = z))
tmesh <- quadmesh::triangmesh(rr, triangles = TRUE) ## triangles in dev-only
## mesh3d way
qmesh <- as.mesh3d(rr, triangles = FALSE) ## triangles in dev-only
op <- par(mfrow = c(2, 2), mar = par("mar")/1, xaxs = "i", yaxs = "i", xpd = F)
plot(t(qmesh$vb[1:2, ]), asp = 1, main = "triangle mesh", axes = FALSE)
mesh_plot(tmesh, add = TRUE, col = viridis::viridis(length(z)))
abline(h = qmesh$vb[2, ], v = qmesh$vb[1, ])
plot(t(qmesh$vb[1:2, ]), asp = 1, main = "quadmesh", axes = FALSE)
mesh_plot(qmesh, add = TRUE)
abline(h = qmesh$vb[2, ], v = qmesh$vb[1, ])
axis(2)
plot(t(qmesh$vb[1:2, ]), asp = 1, main = "image", axes = FALSE)
image(x, y, z, add = TRUE)
abline(h = qmesh$vb[2, ], v = qmesh$vb[1, ])
axis(1)
plot(t(qmesh$vb[1:2, ]), asp = 1, main = "matrix cell centres", axes = FALSE)
points(expand.grid(x, y), pch = "+")
abline(h = qmesh$vb[2, ], v = qmesh$vb[1, ])
axis(1);axis(2)
Created on 2020-05-23 by the reprex package (v0.3.0)