# a) Create small mesh for triangulation example
# using 204 electrodes from epochdata
M <- point_mesh(n = 500, template = "HCGSN256",
sensor_select = unique(epochdata$sensor))
# b) Make triangulation on this mesh
TRI <- make_triangulation(M$D2)
head(TRI)
# c) plot triangulation in 2D
# prepare empty plot
plot(M$D2, type = "n", main = "Triangulation plot",
xlab = "", ylab = "", asp = 1, axes = FALSE)
# create a structure for plotting
x0 <- c()
y0 <- c()
x1 <- c()
y1 <- c()
for (i in 1:nrow(TRI)) {
v_indices <- TRI[i, ]
v_coords <- M$D2[v_indices, ]
x0 <- c(x0, v_coords[1, "x"], v_coords[2, "x"], v_coords[3, "x"])
y0 <- c(y0, v_coords[1, "y"], v_coords[2, "y"], v_coords[3, "y"])
x1 <- c(x1, v_coords[2, "x"], v_coords[3, "x"], v_coords[1, "x"])
y1 <- c(y1, v_coords[2, "y"], v_coords[3, "y"], v_coords[1, "y"])
}
# plot triangulation using segments
segments(x0, y0, x1, y1)
## Note: this code opens a rgl 3D viewer
# d) Plot the result triangulation as 3D wire model using rgl
rgl::open3d()
rgl::wire3d(rgl::mesh3d(M$D3$x, M$D3$y, M$D3$z, triangles = t(TRI)))
Run the code above in your browser using DataLab