We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Points distributed round a circle
Page Index Toggle Pages: 1
Points distributed round a circle (Read 575 times)
Points distributed round a circle
Apr 9th, 2008, 8:37pm
 
Hi,

I'm suffering from a very poor mathematics background here....

Ideally I'd like to be able to specify n points then for those points to be drawn, evenly distributed round a circle - I can happily cope with straight lines its circles that confuse me - can anybody point me to an example?

Thanks
Tomski
Re: Points distributed round a circle
Reply #1 - Apr 9th, 2008, 8:51pm
 
It's really simple really. you just take 360' and divide it by the number of points, and draw one every X degrees.

In processing it's TWO_PI radians in a circle, but the principal is the same.

Code:
float radius=50;
int numPoints=20;
float angle=TWO_PI/(float)numPoints;
for(int i=0;i<numPoints;i++)
{
point(radius*sin(angle*i),radius*cos(angle*i));
}
Re: Points distributed round a circle
Reply #2 - Apr 9th, 2008, 9:02pm
 
Great thanks for the speedy reply - I knew it would be simple, it just takes a little while to become familiar with the building blocks for this type of code;)
Re: Points distributed round a circle
Reply #3 - Apr 10th, 2008, 7:34pm
 
I further developed the "distributed circle" code. which works great, however, the lines drawn (I created a series of points that all link to each other) don't seem to be anti-aliased - what can I do to smooth them? i.e.   smooth(); doesn't do as I expect...  

Code:

// Global variables
float radius = 150; // Size of the circle
int numPoints = 11; // Number of points on the circe
float angle=TWO_PI/(float)numPoints; // Calculate the angle each point is on
float[][] xyArray; // Declare an array

void setup(){
 smooth();
 strokeWeight(1);
 height = 500; // Window height
 width = 500;  // Window width
 background(51);
 // CREATE A LIST OF x & y CO-ORDINATES
 xyArray = new float [numPoints][3]; // Setup the array dimentions
 for(int i=0;i<numPoints;i++) {
   float x = radius*sin(angle*i)+width/2;
   float y = radius*cos(angle*i)+height/2;
   xyArray[i][0] = x; // Store the x co-ordinate
   xyArray[i][1] = y; // Store the x co-ordinate
   xyArray[i][2] = 0.0;
 }
}

void draw(){    
 // Draw the shape
 for(int i=0;i<numPoints;i++){
   float x = xyArray[i][0];
   float y = xyArray[i][1];
   for(int ii=i+1;ii<numPoints;ii++){
     if(ii>i){
       float xx = xyArray[ii][0];
       float yy = xyArray[ii][1];  
       strokeWeight(1);
       line(x, y, xx, yy);
     }
   }
   strokeWeight(1);
   ellipse(x, y, 5, 5);
 }
}

Re: Points distributed round a circle
Reply #4 - Apr 10th, 2008, 7:44pm
 
ignore me - playing around with background colors solves the issue..... boy have I got allot to learn about processing....
Page Index Toggle Pages: 1