Array of circles

This is a discussion on Array of circles within the C Programming forums, part of the General Programming Boards category; I'm about writing a program reads series of cirlces and determines whether circle overlaps with previous input circles or not ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    5

    Array of circles

    I'm about writing a program reads series of cirlces and determines whether circle overlaps with previous input circles or not (Supposed you input 4 circles). Any hints for this would be greate appreciate

    typdef struct Circle
    {
    int x, y;
    double radius;
    };
    typedef struct Distance
    {
    double distance;
    };
    struct Distance Centerdis(Cricle C1, Circle C2);
    struct Distance SumRadius(double r1, double r2)

    int main()
    {
    Circle C[100];
    Distance d1, d2;
    int i;
    for(i = 0; i < 100; i++)
    {
    printf("Enter center circle %: ", i);
    get(C[i])

    ------???? I don't know how to write codes to determine cirlce overlap with some previous circles -------

    }

    struct Distance Centerdis(Cricle C1, Circle C2)
    {
    Distance D;
    ..........
    return D;
    }

    struct Distance SumRadius(double r1, double r2)
    {
    Distance D;
    .................
    return D;
    }

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    Well here's a start...
    Code:
    #define MAX_CIRCLES 100
    
    double centreDist(struct Circle circle1, struct Circle circle2);
    double sumRadius(struct Circle circle1, struct Circle circle2);
    void getCircle(struct Circle * pCircle);
    
    ...
    
    struct Circle circle[MAX_CIRCLES];
    bool overlap;
    unsigned int i, j;
    
    ...
    
    for (i = 0; i < MAX_CIRCLES; i++)
    {
      printf("Enter Circle #%d: ", i);
      getCircle(&circle[i]);
    
      overlap = false;
      for (j = 0; j < i; j++)
      {
        if (centreDist(circle[i], circle[j]) <= sumRadius(circle[i], circle[j]))
        {
          overlap = true;
          break;
        }
      }
    }
    
    ...
    I've changed a few bits and pieces to make life easier for myself, like ignoring the Distance struct which I didn't see the point of, and changing the declaration of sumRadius(). You also need to decide whether or not you consider circles that touch as overlapping. Anyway, hopefully this will get you started...
    DavT
    -----------------------------------------------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 02:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21