Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created August 6, 2022 13:03
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 Hermann-SW/99b7c793f9415686bdb0c34296aef6e1 to your computer and use it in GitHub Desktop.
Save Hermann-SW/99b7c793f9415686bdb0c34296aef6e1 to your computer and use it in GitHub Desktop.
Separating circle created from Octahedron by removing 6 of its 12 edges
look_inside=false;
diff_last=false;
$vpr = [355, 55, 40];
$fn = 25;
$vpt = [0,0,0];
function map_3D(c) = [cos(c[0])*sin(c[1]), sin(c[0])*sin(c[1]), cos(c[1])];
sc = 7.745966692414834 ;
coords =[
[0,90]
, [90,90]
, [180,90]
, [180,180]
, [270,90]
, [0,0]
];
module vertex(_v, c, half=false) {
p = coords[_v];
v = map_3D(p) * sc;
difference(){
color(c) translate(v) sphere(0.5);
if (half) {
la1 = p[0];
ph1 = 90 - p[1];
translate([0, 0, 0]) rotate([0, 0, la1]) rotate([0, -ph1, 0])
translate([sc+0.5, 0]) rotate([90,0,90]) color([0,0,0])
translate([-0.5,-0.5,-1]) cube([1,1,0.4]);
}
}
}
module vtxt(_p1, num) {
p1 = coords[_p1];
la1 = p1[0];
ph1 = 90 - p1[1];
translate([0, 0, 0]) rotate([0, 0, la1]) rotate([0, -ph1, 0])
translate([sc+0.5, 0]) rotate([90,0,90]) color([0,0,0])
linear_extrude(0.01)
text(str(num), size=0.5, halign="center", valign="center");
}
module edge2(_p1,_p2,_e) {
p1 = coords[_p1];
p2 = coords[_p2];
// al/la/ph: alpha/lambda/phi | lxy/sxy: delta lambda_xy/sigma_xy
// https://en.wikipedia.org/wiki/Great-circle_navigation#Course
la1 = p1[0];
la2 = p2[0];
l12 = la2 - la1;
ph1 = 90 - p1[1];
ph2 = 90 - p2[1];
al1 = atan2(cos(ph2)*sin(l12), cos(ph1)*sin(ph2)-sin(ph1)*cos(ph2)*cos(l12));
// delta sigma_12
// https://en.wikipedia.org/wiki/Great-circle_distance#Formulae
s12 = acos(sin(ph1)*sin(ph2)+cos(ph1)*cos(ph2)*cos(l12));
translate([0, 0, 0]) rotate([0, 0, la1]) rotate([0, -ph1, 0])
rotate([90 - al1, 0, 0])
rotate_extrude(angle=s12, convexity=10, $fn=100)
translate([sc, 0]) circle(0.1, $fn=25);
}
difference(){
rotate([0,-$t*360,0]) union(){
color([0,0,1])
edge2( 0 , 1 , 0 );
color([0,0,1])
edge2( 1 , 2 , 1 );
color([0,0,1])
edge2( 2 , 3 , 2 );
color([0,0,1])
edge2( 3 , 4 , 3 );
color([0,0,1])
edge2( 4 , 5 , 4 );
color([0,0,1])
edge2( 5 , 0 , 5 );
vertex( 0 , [0,1,0] , true );
vertex( 1 , [0,1,0] , true );
vertex( 2 , [0,1,0] , true );
vertex( 3 , [0,1,0] , true );
vertex( 4 , [0,1,0] , true );
vertex( 5 , [0,1,0] , true );
difference(){
color([1,1,1, 0.7 ]) translate([0,0,0]) sphere(sc, $fn=180);
if (!diff_last) translate([0,0,0]) sphere(sc-0.1, $fn=180);
}
vtxt( 0 , 0 );
vtxt( 1 , 1 );
vtxt( 2 , 2 );
vtxt( 3 , 3 );
vtxt( 4 , 4 );
vtxt( 5 , 5 );
}
if (diff_last) translate([0,0,0]) sphere(sc-0.1, $fn=180);
if (look_inside) translate([0,0,0]) cube([ 7.745966692414834 , 7.745966692414834 , 7.745966692414834 ]);
}
@Hermann-SW
Copy link
Author

Hermann-SW commented Aug 6, 2022

Left side of 0-1-2-3-4-5-0 spans 0°..270° range.
After adding 360° to coordinates <=180°, right side of 0-1-2-3-4-5-0 spans 270°..540° range.
Solving system of linear equations "mod 2π" is outlined here (Z/pZ with prime p=62831849):
https://math.stackexchange.com/a/4507047/1084297
Fixating only the 6 pole vertices (to span [-1..1] range for x, y and z axis), computing all other sphere polar coordinate vertex positions can be done with solving single system of linear equations "mod 2π".

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