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 › help sampling points from geomtry
Page Index Toggle Pages: 1
help sampling points from geomtry (Read 281 times)
help sampling points from geomtry
Nov 14th, 2008, 9:32pm
 
Hi

I have a sketch that produces a series of circles  around which I want to draw a convex hull, using Lee Byron's mesh library. Any ideas how I could sample points from each circle's perimeters? each one has a different radius....

thanks
Re: help sampling points from geomtry
Reply #1 - Nov 15th, 2008, 11:02am
 
How to you plan to sample? Fixed number of points per circle or each point at fixed distance from others?
The first case is simple: just use trigonometry, incrementing an angle.
Mmm, the second case is simple too, it can be reduced to the first one:
Code:
float radius = 100.0;
float ptDist = 27.0;

float perimeter = TWO_PI * radius;
int ptNb = int(perimeter / ptDist);

void setup()
{
size(400, 400);
translate(200, 200);
smooth();
noLoop();

background(#BBFFCC);
noFill();
stroke(#55AA88);

ellipse(0, 0, 2 * radius, 2 * radius);

stroke(#FF9999);
float angle = 0;
float angleIncrement = TWO_PI / ptNb;
for (int i = 0; i < ptNb; i++)
{
float x = radius * cos(angle);
float y = radius * sin(angle);
angle += angleIncrement;

ellipse(x, y, 3, 3);
}
}
Re: help sampling points from geomtry
Reply #2 - Nov 15th, 2008, 8:23pm
 
here's my noob dumb question - if I were to want the drawn ellipses along the perimeter to be used in my aforementioned problem, how would I store these points? I'm drawing blanks on  this one. Would I put them into some sort of collection, or array? Is there even such a thing as a point? or would they be "vector"s ?

thanks for the demo and help!
Re: help sampling points from geomtry
Reply #3 - Nov 15th, 2008, 8:51pm
 
Recently, I would said to create a simple point class, but now (with the latest versions of Processing), you can use the fine PVector class, just made for this usage!

And yes, you can put your collection of points in an ArrayList. I shown an example usage at bubble up recursion.
Re: help sampling points from geomtry
Reply #4 - Nov 16th, 2008, 9:45am
 
just use normal float arrays:

Code:


float radius = 100.0;
float ptDist = 27.0;

float perimeter = TWO_PI * radius;
int ptNb = int(perimeter / ptDist);

float[] xValues, yValues;

void setup()
{
size(400, 400);
translate(200, 200);
smooth();

background(#BBFFCC);
noFill();
stroke(#55AA88);

ellipse(0, 0, 2 * radius, 2 * radius);

stroke(#FF9999);
float angle = 0;
float angleIncrement = TWO_PI / ptNb;

xValues = new float[0];
yValues = new float[0];

for (int i = 0; i < ptNb; i++)
{
float x = radius * cos(angle);
float y = radius * sin(angle);
angle += angleIncrement;

xValues = append( xValues, x );
yValues = append( yValues, y );
}
}

void draw ()
{
translate(200, 200);
for ( int i = 0; i< xValues.length; i++ )
{
ellipse( xValues[i], yValues[i], 2, 2 );
}
}


F
Page Index Toggle Pages: 1