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

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

$
0
0
It seems I need new "edge3()" that is able to draw edge along the 6 grey vertices positions as stereographic projection:
Interesting how easy that seems to be.
The center tangent through the geodesic circle (in above Wikipedia screenshot) always goes through sphere center.
So JSCAD's "plane.fromPoints(vec3.create(), ...coords)" would be helpful.
The script already had these _3D functions:

Code:

function length_3D(v) {function dist_3D(p, q) {function add_3D(p, q) {function sub_3D(p, q) {function scale_3D(v, f) {function norm_3D(v) {function map_3D(x, y) {function center_3D(p, q, r) {

Only 3D vector multiplication and cross product are needed to implement new plane_3D():

Code:

+function mul_3D(p, q) { return [p[0]*q[0],p[1]*q[1],p[2]*q[2]]; }+function cross_3D(v, w) { return [v[1]*w[2]-v[2]*w[1], v[2]*w[0]-v[0]*w[2], v[0]*w[1]-v[1]*w[0]]; }+function plane_3D(u, v, w) {+    var n = norm_3D(cross_3D(sub_3D(u, v), sub_3D(v, w)));+    n.push(length_3D(mul_3D(u, n)));+    return n;+}

The geodesic circle through two vertices is uniquely determined by the two vertex coordinates and any other third vertex coordinate, I took the middle mapped coordinate. Just scaling the plane normal vector with distance of plane from origin in rightmost vector entry gives geodesic circle center coordinate. A black vertex gets drawn for visual debugging right now:

Code:

+               m = [(coords2D[0][source(G, e)] + coords2D[0][target(G, e)])/2,+                    (coords2D[1][source(G, e)] + coords2D[1][target(G, e)])/2];+            var M = scale_3D(map_3D(m[0], m[1]), sc);+            var V = scale_3D(map_3D(coords2D[0][source(G, e)], coords2D[1][source(G, e)]), sc);+            var W = scale_3D(map_3D(coords2D[0][target(G, e)], coords2D[1][target(G, e)]), sc);+            var pla = plane_3D(M, V, W);+            wlog("vertex(", scale_3D(pla, pla[3]), ",[0,0,0]);");
Screenshot from 2024-09-05 07-54-43.png

The last piece missing for implementation of "edge3()" is just move to the right position and use OpenSCAD's rotate_extrude()
Image
with the apropriate angle less than 360° ...

Statistics: Posted by HermannSW — Thu Sep 05, 2024 6:04 am



Viewing all articles
Browse latest Browse all 4151

Trending Articles