Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active May 23, 2025 12:14
Show Gist options
  • Save Hermann-SW/3950cd4da9f955a4562066b74a0f573c to your computer and use it in GitHub Desktop.
Save Hermann-SW/3950cd4da9f955a4562066b74a0f573c to your computer and use it in GitHub Desktop.
K_{3,3} embedded on a Möbius strip (with Bezier curve edges)
"use strict";
const jscad = require("@jscad/modeling");
const { vec2, vec3} = jscad.maths;
const { bezier} = jscad.curves;
const { rotate, scale, translate } = jscad.transforms;
const { cuboid, sphere, cylinder } = jscad.primitives;
const { colorize } = jscad.colors;
const r=40;
const w=20;
const t=0.001;
let edgeCylinder = cylinder({height: 1, radius: 0.3}); // cached
function edge(v, w) {
let d = vec3.subtract(vec3.create(), w, v);
let m = vec3.lerp(vec3.create(), v, w, 0.5);
let R = [0, Math.acos(d[2] / vec3.length(d)), Math.atan2(d[1], d[0])];
let S = [1, 1, vec3.length(d)];
return translate(m, rotate(R, scale(S, edgeCylinder)));
}
function vertex(c) {
return translate(c, sphere({radius: 1.6}));
}
function xyz(a) {
return vec3.rotateZ(vec3.create(),
vec3.add(vec3.create(),
vec3.rotateY(vec3.create(),
[0,0,a[1]],
[0, 0, 0],
a[0]/2),
[r, 0, 0]),
[0, 0, 0],
a[0]);
}
function moebius_edge(a) {
const n = 100;
let ret = [];
let from = a[0];
let i = 1;
let b = bezier.create(a);
while (i <= n) {
let to = bezier.valueAt(i / n, b);
ret.push(edge(xyz(from), xyz(to)));
from = to;
i += 1;
}
return ret;
}
function moebius_strip(r, w, t) {
var ret = [];
var step = 0.5/180.0*Math.PI;
var azimuth;
var x;
var y;
for(azimuth = 0; azimuth <= 2*Math.PI; azimuth += step) {
x = r * Math.cos(azimuth);
y = r * Math.sin(azimuth);
ret.push(translate([x, y, 0],rotate([0, azimuth/2, azimuth],cuboid({size: [t, 128*step, w]}))));
}
return ret;
}
function main() {
let Vs = [
[13*Math.PI/8,-3],
[14*Math.PI/8,-3],
[15*Math.PI/8,-3],
[13*Math.PI/8,3],
[14*Math.PI/8,3],
[15*Math.PI/8,3],
[12*Math.PI/8,13],
[15.9*Math.PI/8,13],
[15.9*Math.PI/8,-16],
[14*Math.PI/8,-11],
[0*Math.PI/8,-4],
[0*Math.PI/8,7],
[2*Math.PI-0.0001,4],
[2*Math.PI-0.0001,-7],
];
let Es = [[1, 3], [1, 4], [1, 5], [0, 3], [2, 5],
[0, 6, 4],
[2, 7, 4],
[3, 8, 10],
[5, 9, 13],
[0, 11], [2, 12]
];
var out = [];
Vs.forEach(function(v,i){
if(i<6)
out.push(colorize([1,0.5,0],vertex(xyz(v))))
})
Es.forEach(function (e) {
out.push(colorize([1, 1, 0], moebius_edge(e.map(function (v){return Vs[v]}))));
});
return [
colorize([0.66, 0.0, 0.66],moebius_strip(r,w,t)),
out,
];
}
module.exports = { main };
@Hermann-SW
Copy link
Author

Hermann-SW commented May 21, 2025

JSCAD app link to play with. Below view when clicking on corner TOP/FRONT/RIGHT.
Screenshot from 2025-05-21 22-16-37

@Hermann-SW
Copy link
Author

JSCAD app link to play with for new revision with Bezier cuerve edges.
Below view when clicking on corner TOP/FRONT/RIGHT.
image

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