Skip to content

Instantly share code, notes, and snippets.

@stla
stla / TennisBallCheckerBoardFourCorners.R
Last active September 27, 2023 10:04
Tennis ball with checkerboard texture
library(cgalMeshes)
library(rgl)
# https://laustep.github.io/stlahblog/posts/TennisBall.html ####
f <- function(x, y, z) { # Enneper surface: f=0
64*z^9 - 128*z^7 + 64*z^5 - 702*x^2*y^2*z^3 - 18*x^2*y^2*z +
144*(y^2*z^6-x^2*z^6) + 162*(y^4*z^2-x^4*z^2) + 27*(y^6-x^6) +
9*(x^4*z+y^4*z) + 48*(x^2*z^3+y^2*z^3) - 432*(x^2*z^5+y^2*z^5) +
81*(x^4*y^2-x^2*y^4) + 240*(y^2*z^4-x^2*z^4) - 135*(x^4*z^3+y^4*z^3)
}
@stla
stla / SpaceBackground.png
Last active September 7, 2023 09:31
Torus with metamorphosing Weierstrass texture
SpaceBackground.png
@stla
stla / runcinatedTesseract.R
Last active August 8, 2023 10:21
Runcinated tesseract (tetrahedra only) with R
library(rgl)
library(Rvcg)
# vertices ####
nvertices <- 64L
vertices <-
rbind(
c(-1, -1, -1, -1 - sqrt(2)),
c(1, -1, -1, -1 - sqrt(2)),
c(-1, 1, -1, -1 - sqrt(2)),
@stla
stla / rotoide.pov
Created August 1, 2023 12:13
Rotoide with POV-Ray
#version 3.8;
global_settings { assumed_gamma 1 }
#include "colors.inc"
#include "textures.inc"
/* camera */
camera {
location <-11, 7,-32>
look_at 0
angle 45
@stla
stla / closedTube.jl
Last active August 4, 2023 18:26
Closed tubular path with Julia
using LinearAlgebra
using Quaternions
using Meshes
using MeshViz
using GLMakie
function quaternionFromTo(u, v)
re = 1 + sqrt((1.0 + dot(u, v)) / 2.0)
w = cross(u, v) / 2.0 / re
return Quaternion(re, w[1], w[2], w[3])
@stla
stla / gyroGreatDodecicosahedron.R
Last active August 8, 2023 10:24
Hyperbolic great dodecicosahedron
library(rgl)
triangulateFace <- function(face) { # only for convex face !
M <- matrix(NA_integer_, nrow = 3L, ncol = length(face)-2L)
for(i in 2L:(length(face)-1L)) {
M[, i-1L] <- c(face[1L], face[i], face[i+1L])
}
M
}
@stla
stla / greatDodecicosahedron.R
Last active July 23, 2023 12:30
Great dodecicosahedron
triangulateFace <- function(face) { # only for convex face !
M <- matrix(NA_integer_, nrow = 3L, ncol = length(face)-2L)
for(i in 2L:(length(face)-1L)) {
M[, i-1L] <- c(face[1L], face[i], face[i+1L])
}
M
}
# http://dmccooey.com/polyhedra/GreatDodecicosahedron.html
C0 = (3 - sqrt(5)) / 4
@stla
stla / .gitignore
Last active July 22, 2023 03:24
optparse (R)
*.Rproj
.Rproj.user/
.Rhistory
@stla
stla / .gitignore
Last active July 22, 2023 03:18
Batch files Windows
*.Rproj
@stla
stla / invertedCube.R
Created July 20, 2023 07:28
Inverted cube
library(rgl)
iota <- function(x) x / c(crossprod(x))
q <- cgalMeshes:::quaternionFromTo(c(1, 1, 1)/sqrt(3), c(1, 0, 0))
R <- onion::as.orthogonal(q)
cube <- as.tmesh3d(
translate3d(