nerdcraft
YaBB Newbies
Offline
Posts: 7
Re: noob - determine variance from radius and tang
Reply #2 - Aug 21st , 2008, 2:49am
Basically the idea is to plot a series of points in the sunflower head spiral. I've found that if you draw lines from sucessive points in the fibonacci sequence, you get some nice-looking flower petals. However, after a time, the petals simply turn into circle-looking spirals. Also, the larger fibonacci numbers start out looking like radii of the circle -- which I don't want either. So basically I want to loop through the array of points, and draw lines if they aren't too close, in degrees, to a radius or a tangent of the centerpoint. The life-cycle of a spiral is like this: lower fibonacci numbers start off far from being a radius, and quickly grow to being a tangent. Higher numbers start out closer to the radius, and grow to become a tangent much later. So basically, for each fibonacci number, there is only a range of line segments that I want to draw. Here's a page that explains what I'm trying to do: http://www.math.uic.edu/~howard/version5/spirals4v5.html There is probably a way to mathematically know beforehand when the spiral arms will probably look tangent-like, but for right now I don't know it, and this will hopefully help me figure out what it is. Here goes ( remember it's still in development): int h = 400; int w = 400; float x_center = w / 2; float y_center = h / 2; int seed_size = 4; int iterations = 0; int max_iterations = 100; float points[][] = new float[max_iterations + 1][2]; boolean ascend = false; boolean two = false; boolean three = false; boolean five = false; boolean eight = false; int j = 0; void setup() { size ( h,w); background ( 125, 125, 125); stroke( 100, 203, 12 ); // set up for the array of points float phi = ( sqrt(5) + 1 ) / 2; float theta; int distance_factor = 20; float r; for ( int i = 0; i < max_iterations; i++ ) { theta = ( ( 2 * PI ) / phi ) * i; r = sqrt(i); points[i][0] = r * cos(theta) * distance_factor; points[i][1] = r * sin(theta) * distance_factor; } } void draw() { background ( 125, 125, 125); for ( int i = 0; i < max_iterations; i++ ) { stroke( 0, 0, 0 ); ellipse( x_center - points[i][0], y_center - points[i][1], seed_size, seed_size); stroke( 255,0,0 ); j = i + 8; if ( j < max_iterations ) { // line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } stroke(0,0,255); j = i + 5; if ( j < max_iterations ) { // line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } stroke( 0, 255,0 ); j = i + 3; if ( j < max_iterations ) { // line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } stroke( 255,0, 255 ); j = i + 13; if ( j < max_iterations ) { // line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } stroke( 255, 255,0 ); j = i + 21; if ( j < max_iterations ) { line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } stroke( 0, 255, 255 ); j = i + 34; if ( j < max_iterations ) { // line( x_center - points[j][0], y_center - points[j][1], x_center - points[i][0], y_center - points[i][1] ); } } /* if ( max_iterations == iterations ) { ascend = false; } else if ( max_iterations == 0 ) { ascend = true; } if ( ascend ) { max_iterations++; } else { max_iterations--; } */ } float lineLength( float x1, float y1, float x2, float y2 ){ return sqrt( pow(abs(x1-x2),2) + pow(abs(y1-y2),2) ); } float findAngle( float x1, float y1, float x2, float y2, float x3, float y3 ) { // x1 and y1 are common points. If there wasn't an intersection, we couldn't have an angle! float slope1 = slope ( x1, y1, x2, y2 ); float slope2 = slope ( x1, y1, x3, y3 ); // tangent of the angle = ( slope1 - slope2 ) / 1 + ( slope1 * slope2 ) float angle_tan = ( slope1 - slope2 ) / 1 + ( slope1 * slope2 ); // return atan2 ( angle_tan ); return 2.1; } float slope( float x1, float y1, float x2, float y2 ) { return ( y2 - y1 ) / ( x2 - x1 ) ; }