Skip to content

Instantly share code, notes, and snippets.

@stla
Last active June 17, 2023 08:41
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/05cfc0346660f7ca3871a4a3704fd4d0 to your computer and use it in GitHub Desktop.
Save stla/05cfc0346660f7ca3871a4a3704fd4d0 to your computer and use it in GitHub Desktop.
Pseudo Hopf torus with holes
# https://mathmod.deviantart.com/art/Pseudo-Hopf-Tori-565531249
library(misc3d)
library(rgl)
cu <- cv <- 0.0000000001
N <- 3
Fx <- function(u,v){ -cos(u+v)/(sqrt(2)+cos(v-u)) }
DFx <- function(u,v){
DFxu = (Fx(u,v)-Fx(u+cu,v))/cu
DFxv = (Fx(u,v)-Fx(u,v+cv))/cv
c(DFxu, DFxv)
}
Fy <- function(u,v){ sin(v-u)/(sqrt(2)+cos(v-u)) }
DFy <- function(u,v){
DFyu = (Fy(u,v)-Fy(u+cu,v))/cu
DFyv = (Fy(u,v)-Fy(u,v+cv))/cv
c(DFyu, DFyv)
}
Fz <- function(u,v){ sin(u+v)/(sqrt(2)+cos(v-u)) }
DFz <- function(u,v){
DFzu = (Fz(u,v)-Fz(u+cu,v))/cu
DFzv = (Fz(u,v)-Fz(u,v+cv))/cv
c(DFzu, DFzv)
}
n1 <- function(u,v){
DFy(u,v)[1]*DFz(u,v)[2]-DFz(u,v)[1]*DFy(u,v)[2]
}
n2 <- function(u,v){
DFz(u,v)[1]*DFx(u,v)[2]-DFx(u,v)[1]*DFz(u,v)[2]
}
n3 <- function(u,v){
DFx(u,v)[1]*DFy(u,v)[2]-DFy(u,v)[1]*DFx(u,v)[2]
}
R <- function(u,v){
sqrt(n1(u,v)^2+n2(u,v)^2+n3(u,v)^2)
}
fx <- function(u,v){
Thickness = (abs(sin(15*u)*cos(15*v)))^7 + .4*((sin(2*N*u)))
Fx(u,v)+Thickness*n1(u,v)/R(u,v)
}
fy <- function(u,v){
Thickness = (abs(sin(15*u)*cos(15*v)))^7 + .4*((sin(2*N*u)))
Fy(u,v)+Thickness*n2(u,v)/R(u,v)
}
fz <- function(u,v){
Thickness = (abs(sin(15*u)*cos(15*v)))^7 + .4*((sin(2*N*u)))
Fz(u,v)+Thickness*n3(u,v)/R(u,v)
}
open3d(windowRect = c(50,50,562,562))
parametric3d(Vectorize(fx), Vectorize(fy), Vectorize(fz),
umin=0, umax=pi, vmin=0, vmax=2*pi, n=300,
color="gold", engine="rgl", smooth = TRUE)
# # -- if you want an animation
M <- par3d("userMatrix")
movie3d(
par3dinterp(
time = seq(0, 1, len = 9),
userMatrix = list(
M,
rotate3d(M, pi, 1, 0, 0),
rotate3d(M, pi, 1, 1, 0),
rotate3d(M, pi, 1, 1, 1),
rotate3d(M, pi, 0, 1, 1),
rotate3d(M, pi, 0, 1, 0),
rotate3d(M, pi, 1, 0, 1),
rotate3d(M, pi, 0, 0, 1),
M
)
),
fps = 100,
duration = 1,
dir = ".",
movie = "zzpic",
convert = FALSE, webshot = FALSE
)
library(gifski)
gifski(
png_files = Sys.glob("zzpic*.png"),
gif_file = "PseudoHopfTorus.gif",
width = 512,
height = 512,
delay = 1/10
)
file.remove(Sys.glob("zzpic*.png"))
@stla
Copy link
Author

stla commented Jun 17, 2023

PseudoHopfTorus

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