Skip to content

Instantly share code, notes, and snippets.

@stla
stla / SteinerChain.jl
Created October 12, 2023 16:21
Steiner chain with Julia
using Meshes
using MeshViz
using GLMakie
using LinearAlgebra
using Makie
using Printf
# image of circle (center, radius) by the inversion
# with center c and power k
function iotaCircle(c, k, center, radius)
@stla
stla / HopfTorus.jl
Created October 12, 2023 15:32
Hopf torus with Julia
using Meshes
using MeshViz
using LinearAlgebra
using GLMakie
using Makie
using ColorSchemes
using Printf
# parameterization of the Hopf torus
function HopfTorus(u, v, nlobes, A)
@stla
stla / LinkedCyclidesCbyC.jl
Created October 12, 2023 12:51
Linked cyclides circle by circle with Julia
using Meshes
using Rotations
import TransformsBase as TB
using MeshViz
using GLMakie
function HopfFiber(q, t)
[
q[1]*cos(t) + q[2]*sin(t),
sin(t)*(1 + q[3]),
@stla
stla / BarthSextic.jl
Created October 12, 2023 10:35
Barth sextic with Julia
using MarchingCubes
import Meshes
using MeshViz
using GLMakie
using Makie
using Printf
# isosurface function f=0
phi = (1 + sqrt(5)) / 2
function f(x, y, z)
@stla
stla / HopfTorusCbyC.jl
Last active October 12, 2023 17:13
Hopf torus with Julia, circle by circle
using Meshes
using MeshViz
using GLMakie
function HopfTorus(u, nlobes, A)
t = [0, pi / 2, pi]
cos_v = cos.(t)
sin_v = sin.(t)
B = pi / 2 - (pi / 2 - A) * cos(u * nlobes)
C = u + A * sin(2 * u * nlobes)
@stla
stla / torusThreePoints.R
Created October 3, 2023 15:04
Torus whose centerline passes through three given points (R)
library(rgl)
#~~ Torus passing by three points ~~####
## cross-product ###
crossProduct <- function(u, v) {
c(
u[2L]*v[3L] - u[3L]*v[2L],
u[3L]*v[1L] - u[1L]*v[3L],
u[1L]*v[2L] - u[2L]*v[1L]
@stla
stla / Octahelix.R
Last active September 30, 2023 12:48
Boerdijk-Coxeter helix (tetrahelix)
library(rgl)
# tetrahedra vertices
r <- 3*sqrt(3)/10
theta <- acos(-2/3)
h <- 1/sqrt(10)
n <- 20
i <- 1:n
p <- cbind(r*cos(i*theta), r*sin(i*theta), i*h)
@stla
stla / TorusKnot4D.R
Created September 30, 2023 09:56
Torus knots 4D
library(rgl)
library(cgalMeshes)
# trefoil (2,3) ####
p <- function(theta, phi) {
c(
cos(theta)*cos(phi), cos(theta)*sin(phi),
sin(theta)*cos(1.5*phi), sin(theta)*sin(1.5*phi)
)
}
@stla
stla / CliffordTorusHandle.R
Created September 29, 2023 13:57
Clifford torus handle
library(rgl)
library(cgalMeshes)
p <- function(theta, phi) {
c(
cos(theta)*cos(phi), cos(theta)*sin(phi),
sin(theta)*cos(phi), sin(theta)*sin(phi)
)
}
@stla
stla / HopfToriSphericalTrochoidProfile.R
Last active September 25, 2023 23:01
Hopf tori with spherical trochoids as profile curves
library(rgl)
library(cgalMeshes)
# Hopf fiber
HopfFiber <- function(p, t) {
c(
p[3L] * cos(t) + p[2L] * sin(t),
p[2L] * cos(t) - p[3L] * sin(t),
sin(t) * (1 + p[1L]),
cos(t) * (1 + p[1L])