JSCAD for planar graph embeddings onto (unit) sphere

Since some months I work on multilanguage "planar graph playground":
https://github.com/HermannSW/planar_graph_playground
Libraries (undirected graph, ...) are implemented in JavaScript/NodeJS, Python and C++.
forall_edges(G, function(e) { ... });
is the JavaScript way of iterating over all edges of undirected graph G,forall_edges(G, lambda e: ...)
the Python way, andforall_edges(G, [&G, &visited, &pftv](edge g) { ... });
the C++ way.First (2D) graph output was done with SVG in browser, then mostly as PostScript. Online demo for displaying fullerenes:
https://hermannsw.github.io/planar_graph_playground/Lately I created OpenSCAD output for planar embedding onto sphere (every planar graph can be embedded onto sphere, with noncrossing great circle arcs as edges, because of a bijection of plane and unit sphere minus north pole). Has lots of spherical computations inside and looks nice (embedding of C60 or "football" fullerene, 20 hexagons and 12 pentagons on 60 vertices):
https://forums.raspberrypi.com/viewtopic.php?t=333342&start=75#p2026845
Two days ago I overcame problems I had with getting JSCAD packages/web running locally, and since then I am on the way to produce same output using JSCAD. Sofar "vertex()", straight line "edge()" and great circle arc "edge2()" have been ported successfully to JSCAD, documented in further postings in that thread:
You can play live with C20 fullerene embedding in your browser:
https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.vertex_edge2.js 
I implemented optional JSCAD output for planar graph playground "node.tetra.js", details here:
https://forums.raspberrypi.com/viewtopic.php?p=2030546#p2030546Until now I played with C20 hand edited for JSCAD, this is newly created C60 fullerene with 60 vertices and 90 edges:
https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.C60_vtype.jsMore vertices and edges than for C20, but design regeneration still done in less than 10 seconds on Intel it Linux Chrome!

I answered the question on whether JSCAD will be performant enough for low design regeneration with 12 spherical pentagons (it is, takes less than 5 seconds on Intel i7 Chrome, with carefully chosen values for gray points/segments), because all fullerenes have exactly 12 pentagons (
12*3*2=72
sp_tria2()
calls, ...), details here:
https://forums.raspberrypi.com/viewtopic.php?p=2029576#p2029576https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.C20_params.js

Done, now "vertex()" optional 3rd parameter "half" works as well:
https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.vertex_half.jsGreen vertices 1, 2, 15 and 16 are forced as "half" vertices, that is a cube of right size gets subtracted from inside. Subtraction can be seen for vertex 1 at "look_inside" hole border. Vertex 2, 15 and 16 cannot be seen on inside anymore, unlike the other vertices with default "half=false":
... vertex(0, [1,0,0]) ,vertex(1, [0,1,0], true) ,vertex(2, [0,1,0], true) ... ,vertex(15, [0,1,0], true) ,vertex(16, [0,1,0], true) ...

Not perfect, but "vtxt()" works now in JSCAD as well:
https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.vtxt.js 
After a problem with spherical triangle implementation (my problem, not JSCAD problem) ...
https://openjscad.nodebb.com/topic/378/problemwithsubtractinghullisthisabug/3?_=1660487451987... now spherical triangle works. I called it three times to fill one spherical pentagon:
,sp_tria(2,1,15) ,sp_tria(2,15,16) ,sp_tria(2,16,3) ...
You can see spherical gray polygon from outside, and nothing of spherical polygon breaks into white sphere difference on the inside:
Click for view+rotate+zoom, design regeneration takes less than 3 seconds on Intel i7 Chrome
(normally I use chromiumbrowser on Raspberry Pi OS, will test that in 2 weeks):
https://www.openjscad.xyz/?uri=https://stammwilbrandt.de/en/forum/JSCAD.spherical_polygon.js
Clicking "Enable Auotozoom" and "Enable Autorotate" results in nice animation ...P.S:
Next step is to port "vtxt()" for adding text labels to vertex sphere, and "half()" for subtracting cube from inner side of vertex sphere, avoiding vertex to shine through to inside for 3Dprinting later.
After that is done, I will make "node.tetra.js" create JSCAD output as alternative to sofar OpenSCAD output. Creating C60 with 12 spherical pentagons JSCAD file and measuring design regeneration time for it will answer whether JSCAD is usable for great circle arc edge embedding of planar graphs onto sphere: 12 spherical pentagons is 12*3=36 spherical triangles, is 72 "sp_tria2()" and 36 differences with "hull()" of 6 points (mini cubes) ... 
@z3dev said in JSCAD for planar graph embeddings onto (unit) sphere:
@HermannSW WOW! Very nice!
I'm very impressed with the speed of the algorithms! I was expecting to wait for minutes before viewing. But the design was viewable almost immediately!
Do you think that any 3D shape can be 'fitted' to a sphere? How about to a cylinder?
Sure, just calculate the correct (3D) coordinates and place whatever you like on sphere. For cylinder just 3D coordinate determination will be different [(theta, phi) polar coordinates for sphere, (h, phi) for cylinder coordinate at height h].
Here I placed text onto the vertex spheres on the sphere for debugging:
https://forums.raspberrypi.com/viewtopic.php?t=333342&start=50#p2023738

@HermannSW I'm not surprised. The boolean functions require memory and CPU, so high resolution spheres will be very slow. However, newer computers are extremely fast now, so please keep making cool designs!

@HermannSW WOW! Very nice!
I'm very impressed with the speed of the algorithms! I was expecting to wait for minutes before viewing. But the design was viewable almost immediately!
Do you think that any 3D shape can be 'fitted' to a sphere? How about to a cylinder?

Added debug feature "look_inside" for the white sphere:
https://forums.raspberrypi.com/viewtopic.php?p=2028520#p2028520
Learned that number of segments for white sphere is a problem when "subtract()" another sphere with radius reduced by 0.1. 180 segments was no problem for OpenSCAD, for JSCAD I did set parameter default to 30.