I’m trying to replicate the “twisted torus” displayed here: Chromatic ice cube 🌈🧊 : generative (not the moving cube, just the main rotating torus shape)
I got close with the Gray’s Klein bottle parametric equations here: Toroidal Nature
I think the main difference is that Gray’s klein bottle sweeps a figure 8 around a circular path, whereas the Reddit reference link looks like it sweeps a square or something, but I’m not sure how to map that difference to parametric equations. Any help is much appreciated!
Here’s the shape I have so far, notice the “ribs” which I am trying to get rid of (they are caused by the figure 8 mentioned above):
Here is my code for the geometry of the above:
const surface = (u: number, v: number, target: Vector3) => {
const a = 4,
n = 3,
m = 2;
const i = (n * u) / 2,
j = (m * u) / 2,
k = Math.sin(2 * v);
const x = (a + Math.cos(i) * Math.sin(v) - Math.sin(i) * k) * Math.cos(j),
y = (a + Math.cos(i) * Math.sin(v) - Math.sin(i) * k) * Math.sin(j),
z = Math.sin(i) * Math.sin(v) + Math.cos(i) * k;
target.set(x, y, z);
};
const geometry = new ParametricGeometry(surface, 100, 100);
Is this relatively close to what you need:
https://codepen.io/boytchev/full/qBLKpjx
There are some options for modifications:
- change line 46:
n=10
→ n=50
to get sharper edges
- change line 47:
t=1.5
→ t=5
to get more twists
5 Likes
@PavelBoytchev that is EXACTLY what I’m looking for. Thank you so much, you’ve made my day!
1 Like
How did you derive the parametric equations?
This is called Math.
I started with a torus. Its parametric equation does two circles – one big circle along the whole torus (using u as parametric angle) and one small circle across the tube (using v as parametric angle).
x = (R+r*cos(v)) * Math.cos(u)
y = (R+r*cos(v)) * Math.sin(u)
z = r*sin(v)
Then I changed the radius r of the small circle so that it is not a circle, but a superellipse. A super ellipse can make a smooth transition from a circle to a square, so instead of a constant radius r, I used:
r = (cos(v)**n + sin(v)**n)**(-1/n)
Finally, I added the twist – this is u and v are angles that go along the two circles, and I made one of the angle to be added to the other angle by a factor t, so instead of cos(v) and sin(v) I used:
cos(v+t*u)
sin(v+t*u)
Thus the overall equation looks like this (R=4):
r = (cos(v)**n + sin(v)**n)**(-1/n)
x = (4 + r*cos(v+t*u)) * cos(u)
y = (4 + r*cos(v+t*u)) * sin(u)
z = r*sin(v+t*u)
You can get all the shapes above by simply changing t and n:
- torus with circular tube: t=0, n=2
- torus with square tube: t=0, n=10
- square torus with a twist: t=1.5, n=10
5 Likes