Creating a xyz graph with points

edited December 2015 in Library Questions

So I've been reading through the gwoptics library trying to figure out which function to use to create a graph. I am receiving a series of X,Y,Z points and am wanting to graph them via XYZ, (the graph doesn't have to be 3d it can be 2d because I am going to export it to a pdf). The only reason I've been looking at 3-d is I want the three axis, Is there a way to do this in the gwoptics library?
Or would I be better off attempting to just draw it and make the axis, then with the points create lines connecting one to another?

Tagged:

Answers

  • Answer ✓

    I'd just draw it myself.

    void setup(){
      size(600,600,P3D);
      rectMode(CENTER);
    }
    
    void draw(){
      background(0);
      translate(width/2,height/2,0);
      scale(3);
      rotateY(map(mouseX,0,width,-PI,PI));
      rotateX(-map(mouseY,0,height,-PI,PI));
    
      stroke(255,0,0);
      fill(255,0,0,128);
      plane();
    
      stroke(0,255,0);
      fill(0,255,0,128);
      rotateX(HALF_PI);
      plane();
    
      stroke(0,0,255);
      fill(0,0,255,128);
      rotateY(HALF_PI);
      plane(); 
    }
    
    void plane(){
      for(int y=-6; y<7; y++){
        for(int x=-6; x<7; x++){
          rect(10*x,10*y,10,10);
        }
      }
    

    }

  • just using the line function? to go from point to point?

  • edited December 2015 Answer ✓
    void setup() {
      size(600, 600, OPENGL);
      rectMode(CENTER);
    }
    
    void draw() {
      background(0);
    
      lights();
    
      translate(width/2, height/2, 0);
    
      scale(3);
      rotateY(map(mouseX, 0, width, -PI, PI));
      rotateX(-map(mouseY, 0, height, -PI, PI));
    
      //point(455, 434, 122);
      for (int i=0; i<30; i+=2) {
        sphereMy(50-i, 30-i, 42-i);
      }
    
      stroke(255, 0, 0);
      fill(255, 0, 0, 128);
      plane();
    
      stroke(0, 255, 0);
      fill(0, 255, 0, 128);
      rotateX(HALF_PI);
      plane();
    
      stroke(0, 0, 255);
      fill(0, 0, 255, 128);
      rotateY(HALF_PI);
      plane();
    }
    
    void plane() {
      for (int y=-6; y<7; y++) {
        for (int x=-6; x<7; x++) {
          rect(10*x, 10*y, 10, 10);
        }
      }
    }
    void sphereMy(float x, float y, float z) {
      pushMatrix();
      noStroke(); 
      fill(255, 111, 11);
      translate(x, y, z); 
      sphere (2); 
      popMatrix();
    }
    
  • Thanks I will work on drawing it out similar to what you have shown

  • credit goes to TfGuy44 obviously

    anyway, you could also use line with 6 params

    line(x1, y1, z1, x2, y2, z2); 
    

    https://www.processing.org/reference/line_.html

    or point with 3 params

    or use PShape with many vertex (with 3 params xyz)

Sign In or Register to comment.