Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Drawing circles

  1. Jun 9, 2009 #1
    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. jcsd
  3. Jun 9, 2009 #2
    Why not take a compass and paper and try it?
  4. Jun 9, 2009 #3
    I did, but it becomes very hard to do as n gets large, especially in the limit as n tends to infinity
  5. Jun 9, 2009 #4
    If you half the radius of the circle during each iteration, you'd get some kind of fractal on the boundary.
  6. Jun 9, 2009 #5
    the radius r is constant
  7. Jun 9, 2009 #6
    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.
  8. Jun 10, 2009 #7
    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 RADIUS 45
    #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;

    deltax = (int) RADIUS*cos(angle);
    deltay = (int) RADIUS*sin(angle);

    setpixel(screen, centerx+deltax, centery+deltay, 255, 255, 255);
    // Draw_Circle(screen, centerx+deltax, centery+deltay, RADIUS, 255);
    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){

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



    void DrawScreen(SDL_Surface* screen, int h)

    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;


    if (screen == NULL )
    return 1;

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



    switch (event.type)
    case SDL_QUIT:
    keypress = 1;
    case SDL_KEYDOWN:
    keypress = 1;


    return 0;
  9. Jun 12, 2009 #8
    wanna post some screenshots? im curious
  10. Jun 12, 2009 #9
    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:

    Last edited: Jun 12, 2009
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook