Skip to content

Instantly share code, notes, and snippets.

@stla
Last active October 2, 2023 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stla/836d149189db9cea3d683868c1520776 to your computer and use it in GitHub Desktop.
Save stla/836d149189db9cea3d683868c1520776 to your computer and use it in GitHub Desktop.
Some tubular objects with rgl (R)
*.png
.Rproj.user
.Rhistory
library(rgl)
p <- 2
q <- 3
epsilon <- 0.1
# cyclidoidal knot curve
ccld <- function(t, a, c, d){
u <- p*t
v <- q*t
d <- d + epsilon
b <- sqrt(a*a-c*c)
den <- a - c * cos(u) * cos(v)
cbind(
(d * (c - a * cos(v) * cos(u)) + b * b * cos(v)) / den,
(b * sin(v) * (a - d * cos(u))) / den,
(b * sin(u) * (c * cos(v) - d)) / den
)
}
t_ <- seq(0, 2*pi, length.out = 200L)
pts <- ccld(t_, a = 1.94, c = 0.34, d = 0.56)
knotMesh <- addNormals(cylinder3d(pts, radius = epsilon, sides = 30L))
# cyclide mesh
ccldMesh <- cgalMeshes::cyclideMesh(1.94, 0.34, 0.56, nu = 150L, nv = 100L)
# plot
open3d(windowRect = c(50, 50, 562, 562))
bg3d(rgb(54, 57, 64, maxColorValue = 255))
view3d(-15, -50, zoom = 0.75)
shade3d(ccldMesh, col = "gold")
shade3d(knotMesh, col = "navy")
# animation ####
movie3d(spin3d(axis = c(0, 0, 1), rpm = 10),
duration = 6, fps = 20,
movie = "zzpic",
dir = ".",
convert = FALSE,
webshot = FALSE,
startTime = 1/20)
library(gifski)
gifski(
png_files = Sys.glob("zzpic*.png"),
gif_file = "cyclideKnot.gif",
width = 512,
height = 512,
delay = 1/15
)
pngfiles <- Sys.glob("zzpic*.png")
file.remove(pngfiles)
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment