# Drawing circles

1. Jun 9, 2009

### exmachina

Try drawing this mentally:

Start with a circle of radius r, draw n number of points spaced evenly on the circle. at each point on the circle draw another circle of radius r, once again with n number of points. What sort of a picture would one get repeating this process a million times, and as n tends to infinity and r tends to some very small non-zero quantity?

I was told that: for n = 1, 2, 3, 4, or 6, it looks like a bunch of lines connected together at points in a regular way, like an infinite graph. For any other n, it just fills the whole plane.

But I still can't visualize it. This is a preliminary to an extension of non-flat surfaces (ie. repeat the process only this time on a riemannian manifold)

Last edited: Jun 9, 2009
2. Jun 9, 2009

### TVP45

Why not take a compass and paper and try it?

3. Jun 9, 2009

### exmachina

I did, but it becomes very hard to do as n gets large, especially in the limit as n tends to infinity

4. Jun 9, 2009

### Dragonfall

If you half the radius of the circle during each iteration, you'd get some kind of fractal on the boundary.

5. Jun 9, 2009

6. Jun 9, 2009

### flatmaster

I don't see a pattern in anything other than n=2,4. Put the center of the circle at the origin. If you take the example n=5, the x and y coordinates of four of the points contain pi. I don't see anything other than noise comming out.

7. Jun 10, 2009

### exmachina

So I wrote a program , it definitely does seem to pack for n = 1,2,3,4,6

#include <stdio.h>
#include <SDL/SDL.h>
//#include <SDL/SDL_draw.h>
#include <math.h>

#define WIDTH 4000
#define HEIGHT 2000
#define BPP 4
#define DEPTH 32
#define ORIGINX WIDTH/2
#define ORIGINY HEIGHT/2

#define NUMPOINTS 5
#define PI 3.1415926
#define SEARCHDEPTH 11

void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
{
Uint32 *pixmem32;
Uint32 colour;

colour = SDL_MapRGB( screen->format, r, g, b );
int ytimesw = y*screen->pitch/BPP;

pixmem32 = (Uint32*) screen->pixels + ytimesw + x;
*pixmem32 = colour;
}

void drawcircle(SDL_Surface *screen, int centerx, int centery, int iter)
{

int deltax;
int deltay;

double dangle = 2*PI/NUMPOINTS; // starts at pi/3
double angle;

for(angle = 0; angle < 2*PI ; angle+=dangle)
{

if (iter>=SEARCHDEPTH) {
return 0;
}

setpixel(screen, centerx+deltax, centery+deltay, 255, 255, 255);
// Draw_Circle(screen, centerx+deltax, centery+deltay, RADIUS, 255);
/*DEBUG
printf ("cos of angle %f\n", cos(angle));
printf ("angle: %f\n", angle);
printf ("deltax: %d\n", deltax);
printf ("deltay: %d\n", deltay);
printf ("iteration: %d\n", iter);
*/

//updates the screen only 1/5th of the time
if (iter==SEARCHDEPTH/2){
SDL_Flip(screen);
}

iter++;
drawcircle(screen, centerx+deltax, centery+deltay, iter);
iter--;

}

}

void DrawScreen(SDL_Surface* screen, int h)
{

if(SDL_MUSTLOCK(screen))
{
if(SDL_LockSurface(screen) < 0) return;
}

drawcircle(screen, ORIGINX, ORIGINY, 0);

if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);

}

int main(int argc, char* argv[])
{
SDL_Surface *screen;
SDL_Event event;

int keypress = 0;
int h=0;

if( SDL_Init( SDL_INIT_EVERYTHING ) == -1)
{
return 1;
}

screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE);

if (screen == NULL )
{
return 1;
}

SDL_WM_SetCaption( "Drawing the 'circles' ... ", NULL );

//DrawScreen(screen,h++);

while(!keypress)
{
DrawScreen(screen,h++);

while(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
keypress = 1;
break;
case SDL_KEYDOWN:
keypress = 1;
break;
}
}
}

SDL_Quit();

return 0;
}

8. Jun 12, 2009

### boboYO

wanna post some screenshots? im curious

9. Jun 12, 2009

### exmachina

here's what it looks like for 3 iterations, the intensity scale is from dark red (very few points) to yellow (medium # of points) to white ( a lot of points). note that right now, the algorithm is quite terrible. Unfortunately it grows exponentially (ie. n^i n = number of points, i = iterations) so 50 points per circle, 5 iterations, 312 million points. I havent found any smart ways to break the exponentiality yet.

#### Attached Files:

• ###### snapshot2.png
File size:
38.4 KB
Views:
98
Last edited: Jun 12, 2009