JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    JSCAD for planar graph embeddings onto (unit) sphere

    Design Discussions
    2
    10
    1388
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Hermann-SW
      Hermann-SW last edited by

      Since some months I work on multi-language "planar graph playground":
      https://github.com/Hermann-SW/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, and forall_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://hermann-sw.github.io/planar_graph_playground/

      Lately I created OpenSCAD output for planar embedding onto sphere (every planar graph can be embedded onto sphere, with non-crossing 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
      alt text

      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:
      alt text

      You can play live with C20 fullerene embedding in your browser:
      https://www.openjscad.xyz/?uri=https://stamm-wilbrandt.de/en/forum/JSCAD.vertex_edge2.js

      z3dev 1 Reply Last reply Reply Quote 0
      • Hermann-SW
        Hermann-SW last edited by

        I implemented optional JSCAD output for planar graph playground "node.tetra.js", details here:
        https://forums.raspberrypi.com/viewtopic.php?p=2030546#p2030546

        Until 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://stamm-wilbrandt.de/en/forum/JSCAD.C60_vtype.js

        More vertices and edges than for C20, but design regeneration still done in less than 10 seconds on Intel it Linux Chrome!
        https://forums.raspberrypi.com/download/file.php?id=56198

        1 Reply Last reply Reply Quote 0
        • Hermann-SW
          Hermann-SW @Hermann-SW last edited by Hermann-SW

          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#p2029576

          https://www.openjscad.xyz/?uri=https://stamm-wilbrandt.de/en/forum/JSCAD.C20_params.js
          alt text

          1 Reply Last reply Reply Quote 0
          • Hermann-SW
            Hermann-SW @Hermann-SW last edited by

            Done, now "vertex()" optional 3rd parameter "half" works as well:
            https://www.openjscad.xyz/?uri=https://stamm-wilbrandt.de/en/forum/JSCAD.vertex_half.js

            Green 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)
            ...
            

            https://stamm-wilbrandt.de/en/forum/JSCAD.vertex_half.js.png

            1 Reply Last reply Reply Quote 0
            • Hermann-SW
              Hermann-SW @Hermann-SW last edited by

              Not perfect, but "vtxt()" works now in JSCAD as well:
              https://www.openjscad.xyz/?uri=https://stamm-wilbrandt.de/en/forum/JSCAD.vtxt.js

              https://stamm-wilbrandt.de/en/forum/JSCAD.vtxt.js.png

              Hermann-SW 1 Reply Last reply Reply Quote 0
              • Hermann-SW
                Hermann-SW @Hermann-SW last edited by Hermann-SW

                After a problem with spherical triangle implementation (my problem, not JSCAD problem) ...
                https://openjscad.nodebb.com/topic/378/problem-with-subtract-ing-hull-is-this-a-bug/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:
                https://stamm-wilbrandt.de/en/forum/JSCAD.spherical_polygon.js.png

                Click for view+rotate+zoom, design regeneration takes less than 3 seconds on Intel i7 Chrome
                (normally I use chromium-browser on Raspberry Pi OS, will test that in 2 weeks):
                https://www.openjscad.xyz/?uri=https://stamm-wilbrandt.de/en/forum/JSCAD.spherical_polygon.js
                Clicking "Enable Auoto-zoom" and "Enable Auto-rotate" 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) ...

                Hermann-SW 1 Reply Last reply Reply Quote 0
                • Hermann-SW
                  Hermann-SW @z3dev last edited by

                  @z3dev said in JSCAD for planar graph embeddings onto (unit) sphere:

                  @Hermann-SW 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
                  alt text

                  1 Reply Last reply Reply Quote 0
                  • z3dev
                    z3dev @Hermann-SW last edited by

                    @Hermann-SW 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!

                    1 Reply Last reply Reply Quote 0
                    • z3dev
                      z3dev @Hermann-SW last edited by

                      @Hermann-SW 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?

                      Hermann-SW 1 Reply Last reply Reply Quote 0
                      • Hermann-SW
                        Hermann-SW last edited by

                        Added debug feature "look_inside" for the white sphere:
                        https://forums.raspberrypi.com/viewtopic.php?p=2028520#p2028520
                        alt text

                        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.

                        z3dev Hermann-SW 3 Replies Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB | Contributors