Quick Yes or No, Please... (3d)

Not yet a user. Need to decide if an idea can be done at all before I dive in.

Picture if you will, a record player turntable on top of which are hills and valleys sculpted from clay. The viewer would want to rotate table and also incline or decline his view. What the turntable surface would represent are X and Y locations of a sheet laser shown through falling mist, this while the hill and valley heights represent the light extinction values resulting from spray cone mist falling perpendicularly through that plane.

I can use Perl to extract said values for X, Y and Z from the output file of an instrument called an En Urga SetSCAN 600. My question, therefore, is whether I can create such a view with Processing 3.

My alternate thought was to translate the XYZ data into the 3D CAD format STEP. I'm sure that would work, but might not be pretty. A friend recommended looking into either D3.js or Processing 3.

Answers

  • Have you had a look at the 3D tutorial? I imagine what you're after is possible though I've not done any 3D work myself. You can certainly change view positions and light levels.

    https://www.processing.org/tutorials/p3d/ https://processing.org/examples/perspective.html

  • Processing 3 is but one of plural suggestions offered on other forums. I'm rather hoping for someone who actually knows to say "yes" or else to say "no". That would save me the need of reviewing a plethora of different tutorials on various forums.

    Lazy of me to a degree, but I work enough overtime as it is, all on salary and so not paid. I'll put off reviewing those for after when someone who knows answers with "yes" rather than "no". Nevertheless, thank you for pointing those out.

  • Answer ✓

    the devil hides in details

    the answer is yes, but since processing is general purpose,e.g. the speed could go down or some other details could appear

  • Answer ✓

    test yourself:

    // from https://processing.org/examples/distance2d.html
    
    // This is a list of my circles / nodes from the class Node
    ArrayList<Node> nodes = new ArrayList();
    
    Node curr=null; 
    
    float max_distance;
    
    //Arcball arcball;
    
    float zoomScale1   = 0.0;
    float angleRotateY  = 0.0;
    float angleRotateX  = 0.0;
    boolean automaticRotateY = true; 
    boolean holdLeft    = false; // mouse
    boolean holdCenter  = false; // mouse
    
    final int GAME=0;
    int state=GAME; 
    
    // -------------------------------------------------
    
    void setup() {
      size(1640, 760, P3D); 
      noStroke();
    
      sphereDetail(13); // level of detail 
    
      // if(mousePressed) 
      max_distance = dist(0, 0, width, height);
    
      for (int i = -300; i <= +300; i += 20) { // used as x
        for (int j = -300; j <= +300; j += 20) {  // used as z
    
          float y_value=10;   //  used as y-value
          // y_value = dist(mouseX, mouseY, i, j);  //  used as y-value
    
          PVector p1=new PVector(144, 144); 
          PVector p2=new PVector(44, 244); 
          PVector p3=new PVector(4, 24);
    
    
          //if (dist(i, j, p1.x, p1.y)<220)
          //  y_value =  80 -   (1/dist(i, j, p1.x, p1.y));
          //else if (dist(i, j, p2.x, p2.y)<220)
          //  y_value = 70- dist(i, j, p1.x, p1.y);
          //else  y_value = max( dist(i, j, p3.x, p3.y), 0);
    
    
          y_value = 455 ;   
    
          if (dist(i, j, p1.x, p1.y)<220)
            y_value +=   (dist(i, j, p1.x, p1.y));
          else if (dist(i, j, p2.x, p2.y)<220)
            y_value +=  dist(i, j, p1.x, p1.y);
          else  y_value +=   dist(i, j, p3.x, p3.y);
    
    
          //y_value = 44; 
    
          if (random(100)>92) {
            y_value+=random(-144, 90);
          }
    
          // normalize 
          y_value = y_value/max_distance * 66;
    
          //  y_value = 10; 
          // ellipse3D(i, y_value*10, j, 17);
    
          color col = color(random(44, 255), random(44, 255), random(44, 255)); 
    
          nodes.add(new Node(i*1.0, y_value*10.0, j*1.0, col, 17));
        }
      }
    }
    
    void draw() {
      background(0);
      hint(ENABLE_DEPTH_TEST); // enable Depth Test.
      lights(); 
    
      if (holdLeft) {
        angleRotateY = map (mouseX, 0, width, 0, TWO_PI); //   angleRotateY  += (mouseY-pmouseY) / 2;
        angleRotateX = map (mouseY, 0, height, 0, TWO_PI);
      }
    
      if (holdCenter) {
        if (curr==null)
          for (Node n : nodes) {
            if (n.mouseOver()) {
              curr=n;
              curr. c_fill=color(255, 2, 2); // RED
              // n.ypos--;//=max( dist(n.xpos, n.ypos, mouseX, mouseY), 0) ;
              break;
            }
          }
      }
    
      camera(0, 0, 500+zoomScale1, 
        0, 220, 0, 
        0, 1, 0);
    
    
      rotateX(angleRotateX); 
      rotateY(angleRotateY);
    
      if (automaticRotateY)
        angleRotateY+=.01;
    
      fill(255, 0, 0); 
      //  ellipse3D(0, 0, 0, 17); 
    
      fill(255);
      for (Node n : nodes) {
        n.display();
      }
    
      // HUD ---------------------------------
    
      if (true) {
        camera();
        hint(DISABLE_DEPTH_TEST); // Disable Depth Test.
        noLights(); 
        fill(255, 0, 0); 
        text("Left Mouse and drag: rotate. \nSelect sphere with RIGHT mouse, hold mouse and hit + and - key: change its height."
          +" \nMousewheel to scale ("
          +zoomScale1
          +"). \nHit space bar to toggle automatic rotation.", 
          20, 20);
      }
    }
    
    void keyPressed() {
      switch(key) {
      case '+':
        if (curr!=null) 
          curr.ypos++;
        break; 
    
      case '-':
        if (curr!=null) 
          curr.ypos--;
        break;
    
      case ' ':
        automaticRotateY = !automaticRotateY;
        break;
      }//switch
    }
    
    //-------------------------------------------------------
    
    void mouseWheel(MouseEvent event) {
    
      //This method controls zoomScale1 variable
    
      // (works only in state Game)
      if (state!=GAME)
        return;
    
      if (event.getCount()==-1) {
        zoomScale1 += 10.1;
      } else if (event.getCount()==1) {
        zoomScale1 -= 10.1;
      }
    } 
    
    
    void mousePressed() {
      //
      if (mouseButton==LEFT) 
        holdLeft=true;
      else if (mouseButton==RIGHT)
        holdCenter=true;
    }
    
    void mouseReleased() {
      holdLeft=false;
      holdCenter=false;
      if (curr!=null) {
        curr.c_fill=curr.c_default;
        curr=null;
      }
    }
    
    // ==========================================================
    
    class Node {
    
      float xpos;    // each node has its properties: Position X
      float ypos;    // Position Y
      float zpos;    // Position Y
    
      float x2D, y2D; 
    
      //  color c;       // color for stroke
      color c_fill;      // color for fill
      color c_default;   // 
    
      float radius;  // radius / size
    
      Node(float tempX, float tempY, float tempZ, 
        color tempc_fill, 
        float tempRadius) {
        // each node gets its properties here in the Constructor
        xpos = tempX;
        ypos = tempY;
        zpos = tempZ;
        // c = tempColor;
        c_fill = tempc_fill;
        c_default=c_fill; 
        radius = tempRadius;
      } // Constructor
      //
      void display () {
        // noFill();
        fill(c_fill); 
        smooth();
        // use the individual properties to draw one node
        // stroke(c);
        // ellipse (xpos, ypos, radius, radius);
        // ellipse3D(i, y_value*10, j, 17);
        ellipse3D(xpos, ypos, zpos, 17);
      } // func
    
      void ellipse3D(float x, float y, float z, float size) {
        noStroke();
        // fill(255);
        pushMatrix();
        noStroke(); 
        translate (x, y, z);
    
        x2D = screenX(0, 0, 0);
        y2D = screenY(0, 0, 0);
    
        sphere(size); 
        popMatrix();
        //if (false)
        //  line3D(x, y, z, 
        //    x, 0, z, 
        //    2, 
        //    color(111) );
      }// func 
      //
    
    
      boolean mouseOver() {
        return (dist(mouseX, mouseY, x2D, y2D)<20);
      }
    
    
      // misc funcs / tools
    
      void line3D(float x1, float y1, float z1, 
        float x2, float y2, float z2, 
        float weight, 
        color colorLine) {
    
        // drawLine was programmed by James Carruthers
        // see http://processing.org/discourse/yabb2/YaBB.pl?num=1262458611/0#9 
    
        PVector p1 = new PVector(x1, y1, z1);
        PVector p2 = new PVector(x2, y2, z2);
        PVector v1 = new PVector(x2-x1, y2-y1, z2-z1);
        float rho = sqrt(pow(v1.x, 2)+pow(v1.y, 2)+pow(v1.z, 2));
        float phi = acos(v1.z/rho);
        float the = atan2(v1.y, v1.x);
        v1.mult(0.5);
        pushMatrix();
        PVector v2 = new PVector ( x1, y1, z1 );
        translate(v2.x, v2.y, v2.z);
        translate(v1.x, v1.y, v1.z);
        rotateZ(the);
        rotateY(phi);
        noStroke();
        fill(colorLine);
    
        box(weight, weight, p1.dist(p2));
        popMatrix();
      } // func
      //
    } // class
    //
    
  • Thank you for this. I will buy some books and have a go. Nothing is ever so helpful as an actual example.

  • I now have three books. At first glance there seems little in them to do with Z axis as 3rd physical dimension. But Chrisir's example is quite proof enough. Baby steps for me, then, I guess.

Sign In or Register to comment.