Hi, I've created a cone made of random points on the surface, but I get too many points near the apex. How can I get a uniform distribution? Also I get a cone that looks like a diamond, but I want it positioned upside down, like this:
http://trialx.com/curetalk/wp-content/blogs.dir/7/files/2011/05/diseases/Cone-2.gif any tips on what I am doing wrong? Thanks.
The code here describes an animation. I have random points that go forming the cone when I press p.
Copy code
- import processing.opengl.*;
- float vel = 5;
- float velr = 1;
- int nums = 1000;
- int numr = 150;
- int winsize = 600;
- int ballsize = 5;
- float radius = 200;
- float coheight = 300;
- PVector[] randomp = new PVector[numr];
- PVector[] solidp = new PVector[nums];
- float[] cothetas = new float[nums];
- float[] cophis = new float[nums];
- void setup() {
- size(winsize, winsize, OPENGL);
- smooth();
- noStroke();
- starttime = millis();
- for(int i=0; i<numr; i++) {
- randomp[i] = new PVector(random(-winsize/2, winsize/2), random(-winsize/2, winsize/2), random(-winsize/2, winsize/2));
- }
- for (int i=0; i<nums; i++) {
- solidp[i] = new PVector(random(-winsize/2, winsize/2), random(-winsize/2, winsize/2), random(-winsize/2, winsize/2));
- //inizializzazione variabili cono
- cothetas[i] = random(TWO_PI);
- cophis[i] = random(coheight);
- }
- }
- void draw() {
- background(0);
- translate(width/2, height/2);
- rotateX(-PI/6.0);
- rotateY(-PI/6.0);
- //rotateY((-PI/36.0)*frameCount);
- renderBackground();
- if (key == 'p') renderCone(radius, coheight);
- }
- void renderBackground() {
- pushMatrix();
- noFill();
- for (int i=0; i<numr; i++) {
- pushMatrix();
- translate(randomp[i].x, randomp[i].y, randomp[i].z);
- randomp[i].x+=random(-10, 10);
- randomp[i].y+=random(-10, 10);
- randomp[i].z+=random(-10, 10);
- fill(255);
- noStroke();
- ellipse(0, 0, ballsize, ballsize);
- //sphereDetail(3);
- //sphere(ballsize);
- popMatrix();
- }
- for (int i=0; i<nums; i++) {
- pushMatrix();
- translate(solidp[i].x, solidp[i].y, solidp[i].z);
- fill(0, 255, 100);
- noStroke();
- ellipse(0, 0, ballsize, ballsize);
- //sphereDetail(3);
- //sphere(ballsize);
- popMatrix();
- }
- popMatrix();
- }
- void renderCone(float radius, float coheight) {
- float thisradius;
- for (int i=0; i<nums; i++) {
- thisradius = radius * (1-(cophis[i]/coheight));
- println(thisradius);
- rotateZ(cophis[i]);
- rotateX(cothetas[i]);
- if(solidp[i].x>cos(cothetas[i])*thisradius) solidp[i].x-=vel;
- if(solidp[i].x<cos(cothetas[i])*thisradius) solidp[i].x+=vel;
- if(solidp[i].z>sin(cothetas[i])*thisradius) solidp[i].z-=vel;
- if(solidp[i].z<sin(cothetas[i])*thisradius) solidp[i].z+=vel;
- if(solidp[i].y>cophis[i]-coheight/2) solidp[i].y-=vel;
- if(solidp[i].y<cophis[i]-coheight/2) solidp[i].y+=vel;
- }
- }
1