Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5224

Other programming languages • Re: JavaScript graph library, for embedding and drawing planar graphs in 2D and/or sphere surface

$
0
0
Long time no update on planar_graph_playground repo.

Recently I worked on planar graph 6-coloring again, will create a Boost C++ graph library pull request:
viewtopic.php?p=2246134#p2246134
( I like non-overclocked Pi5 creating a maximal planar random graph with 1million edges and then 6-color it in less than 3 seconds !)

Then I remembered my old (Python, NodeJS/JavaScript and C++) code on planar_graph_playground repo.
I found node.straight_line_drawing.3D.js as simplest basis for new development, created new copy, and then removed quite some code:
https://github.com/Hermann-SW/planar_gr ... 349349aaa0

Running

Code:

./rjs node.straight_line_drawing.3D.2.js
creates C20 (dodecahedron) OpenSCAD file x.scad.

The old code
https://github.com/Hermann-SW/planar_gr ... ng.3D.2.js
map_3D() function was too simlistic and did not map the vertices evenly distributed onto the sphere.

I learned that my code did set view so that red vertex is in front of coordinate origin:
initial.png
This view better shows uneven vertex distribution on the sphere:
uneven.png

On Wikipedia dodecahedron (C20) page, the cartesian coordinates are shown:
https://en.wikipedia.org/wiki/Dodecahed ... oordinates

I used them with h=1/phi with phi being the golden ratio to create regular dodecahedron with jscad.app.
No need to think on edges, just use convex hull and little vertex function to get below.
You can open in your browser with this jscad.app URL:
https://stamm-wilbrandt.de/jscadui.dodecahedron.html
regular_dodecahedron.png

Next I will try (variants of) stereographic projection for mapping the computed convex face Tutte embedding in the plane
https://hermann-sw.github.io/planar_graph_playground/
Image
onto the sphere:
it is a bijective mapping of the whole plane onto sphere without north pole.
https://en.wikipedia.org/wiki/Stereographic_projection

With north pole at [0,0,1] and plane at z=-1, I computed mapped point for [x,0,-1] onto the sphere.
The line through [x,0,-1] and [0,0,1] is "(x, 0, -1)+t*(-x, 0, 2)".
Sphere has radius 1, so other than north pole (t=1) has norm 1 as well and satisfies this quadratic equation (x and z coordinates only):

Code:

(x-tx)^2 + (-1+2t)^2 = 1


While I use PARI/GP computer algebra system much more often, it is good to have Raspberry Pi's Mathematica!

Code:

pi@raspberrypi5:~ $ wolframMathematica 14.0.0 Kernel for Linux ARM (64-bit)Copyright 1988-2024 Wolfram Research, Inc.In[1]:= Solve[(x-t*x)^2+(-1+2*t)^2==1,t]                                                                 2                           xOut[1]= {{t -> 1}, {t -> ------}}                              2                         4 + xIn[2]:=                                                                      
So with t=1 the line "(x, -1)+t*(-x, 2)" intersects sphere at north pole (0,1).
For x=2 the other term is 4/8=1/2, and intersection is at (2/2, 0) which is correct.

More to come ...


P.S:
I have a version controlled jscad.app with lots of stuff implemented for (spherical) lattice sphere, that I often use like today to copy out stuff from:
https://hermann-sw.github.io/lattice_sphere_cmp

Statistics: Posted by HermannSW — Thu Aug 22, 2024 8:18 pm



Viewing all articles
Browse latest Browse all 5224

Trending Articles