|
Author |
Topic: Rotating 3D plotted points (Read 473 times) |
|
ssdesign
|
Rotating 3D plotted points
« on: Dec 31st, 2004, 9:16pm » |
|
Hi, let me introduce myself as a new comer to processing. I have written a small program which plots a "Tranguloid Trefoil" 3D surface. I am just plotting it as POINTS. The question is, I now want to move the object and see it in 3D when mousePressed() or mouseMoved() even happens. Any suggestions?? Thanks. here is my code: /////////////////////////////////////////// /////////////////////////////////////////// void setup(){ size(500, 500); background(255); } void loop(){ float u = random(-PI, PI); float v = random(-PI, PI); float sc = 30; float x = sc*(2*sin(3*u) / (2 + cos(v))); float y = sc*(2*(sin(u) + 2*sin(2*u)) / (2 + cos(v + 2*PI / 3))); float z = sc*((cos(u) - 2*cos(2*u))*(2 + cos(v))*(2 + cos(v + 2*PI / 3)) / 4); point(x+width/2, y+height/2, z); stroke(102); } void mouseMoved(){ rotateY(mouseX); rotateX(mouseY); } /////////////////////////////////////////// ///////////////////////////////////////////
|
:: form follows function ::
|
|
|
fjen
|
Re: Rotating 3D plotted points
« Reply #1 on: Jan 1st, 2005, 3:49pm » |
|
try this .. Code: void setup(){ size(500, 500); background(255); Points3d = new Vector(); framerate(20); } float r_step = 0.002; float ry=0.0f; void loop(){ background(120); stroke(0); translate(width/2.0, height/2.0, -200.0); rotateY(ry); ry += r_step; float u = random(-PI, PI); float v = random(-PI, PI); float sc = 30; float x = sc*(2*sin(3*u) / (2 + cos(v))); float y = sc*(2*(sin(u) + 2*sin(2*u)) / (2 + cos(v + 2*PI / 3))); float z = sc*((cos(u) - 2*cos(2*u))*(2 + cos(v))*(2 + cos(v + 2*PI / 3)) / 4); if (Points3d.size() < 1000) Points3d.add(new Point3D(x, y, z)); for (int i=0; i < Points3d.size(); i++) ((Point3D)Points3d.get(i)).draw(); } Vector Points3d; class Point3D { float x, y, z; Point3D (float _x, float _y, float _z) { this.x = _x; this.y = _y; this.z = _z; } void draw() { point(this.x, this.y, this.z); } } |
| as you said, you were "plotting it as points", means you were just drawing pixels in 3d-space. there is no way to rotate something like point() because it's not an object, just a pixel-drawing -method. that's why i created the Point3D-class above to hold and draw the values over and over. see this example for how to rotate things via mouse: RGB Cube /F btw: [ code ] .... [ /code ] without the spaces will give you a code-field in the post. [ link=http... ] ... [ /link ] will give you a textlink ... happy 2005!
|
|
|
|
ssdesign
|
Re: Rotating 3D plotted points
« Reply #2 on: Jan 2nd, 2005, 7:50pm » |
|
thanks fjen, that was really helpful. I shall post the link here once I have something to show to everyone sajid
|
:: form follows function ::
|
|
|
|