Arc around a sphere
in
Contributed Library Questions
•
1 year ago
I am trying to create connection lines that arc around a sphere of points. Here is my current sketch:
- import peasy.*;
- import toxi.geom.Vec3D;
- int NUM_PARTICLES = 5000;
- PeasyCam cam;
- Node nodes[] = new Node[NUM_PARTICLES];
- float radius = 150;
- void setup(){
- size(800, 600, P3D);
- background(255);
- cam = new PeasyCam(this, width);
- for(int i=0; i<NUM_PARTICLES; i++) {
- Node n = new Node(random(0,TWO_PI), random(-1,1));
- nodes[i] = n;
- }
- for(int j=0; j<NUM_PARTICLES; j++) {
- nodes[j].connect(nodes[(int)random(0, nodes.length-1)]);
- }
- };
- void draw(){
- background(255);
- for(int i=0; i<nodes.length; i++){
- Node n = nodes[i];
- n.render();
- }
- };
- class Node extends Vec3D {
- float theta, u;
- Node conn;
- Node(float Theta, float U) {
- theta = Theta;
- u = U;
- x = radius*cos(theta)*sqrt(1-(u*u));
- y = radius*sin(theta)*sqrt(1-(u*u));
- z = u*radius;
- }
- void connect(Node cn) {
- conn = cn;
- }
- void render() {
- pushMatrix();
- translate(x, y, z);
- point(0, 0, 0);
- stroke(0,0,0,20);
- popMatrix();
- }
- }
I'd really appreciate any help.
1