Algorithm for shape calculation (Ellipse)

user2360915

I have n circles that must be perfectly surrounding an ellipse as shown in the picture here :

Ellipse & Circles

In this picture I need to find out the position of each circle around the ellipse, and also be able to calculate the ellipse that will fit perfectly inside those surrounding circles.

The information i know is the radius of each circles (all same), and the number of circles.

Hopefully this time the post is clear. Thanks for your help. Please let me know if you need more explanation.

Spektre

OK as i understand you know common radius of circles R0 and their number N and want to know inside ellipse parameters and positions of everything.

If we convert ellipse to circle then we get this:

const int N=12; // number of satelite circles
const double R=10.0;    // radius of satelite circles
struct _circle { double x,y,r; } circle[N]; // satelite circles

int i;
double x,y,r,l,a,da;
x=0.0;  // start pos of first satelite circle
y=0.0;
r=R;
l=r+r;  // distance ang angle between satelite circle centers
a=0.0*deg;
da=divide(360.0*deg,N);
for (i=0;i<N;i++)
    {
    circle[i].x=x; x+=l*cos(a);
    circle[i].y=y; y+=l*sin(a);
    circle[i].r=r; a+=da;
    }
// inside circle params
_circle c;
r=divide(0.5*l,sin(0.5*da))-R;
c.x=circle[i].x;
c.y=circle[i].y+R+r;
c.r=r;

Circle + circles

[Edit 1]

For ellipse its a whole new challenge (took me two hours to find all quirks out)

const int    N=20;      // number of satelite circles
const double R=10.0;    // satelite circles radius
const double E= 0.7;    // ellipse distortion ry=rx*E
struct _circle { double x,y,r; _circle() { x=0; y=0; r=0.0; } } circle[N];
struct _ellipse { double x,y,rx,ry; _ellipse() { x=0; y=0; rx=0.0; ry=0.0; } } ellipse;

int i,j,k;
double l,a,da,m,dm,x,y,q,r0;
l=double(N)*R;                          // circle cener lines polygon length
ellipse.x =0.0;                         // set ellipse parameters
ellipse.y =0.0;
r0=divide(l,M_PI*sqrt(0.5*(1.0+(E*E))))-R;// aprox radius to match ellipse length for start
l=R+R; l*=l;
m=1.0; dm=1.0; x=0.0;
for (k=0;k<5;k++)                       // aproximate ellipse size to the right size
    {
    dm=fabs(0.1*dm);                    // each k-iteration layer is 10x times more accurate
    if (x>l) dm=-dm;
    for (;;)
        {
        ellipse.rx=r0  *m;
        ellipse.ry=r0*E*m;
        for (a=0.0,i=0;i<N;i++)         // set circle parameters
            {
            q=(2.0*a)-atanxy(cos(a),sin(a)*E);
            circle[i].x=ellipse.x+(ellipse.rx*cos(a))+(R*cos(q));
            circle[i].y=ellipse.y+(ellipse.ry*sin(a))+(R*sin(q));
            circle[i].r=R;    
            da=divide(360*deg,N); a+=da;
            for (j=0;j<5;j++)           // aproximate next position to match 2R distance from current position
                {
                da=fabs(0.1*da);        // each j-iteration layer is 10x times more accurate
                q=(2.0*a)-atanxy(cos(a),sin(a)*E);
                x=ellipse.x+(ellipse.rx*cos(a))+(R*cos(q))-circle[i].x; x*=x;
                y=ellipse.y+(ellipse.ry*sin(a))+(R*sin(q))-circle[i].y; y*=y; x+=y;
                if (x>l) for (;;)       // if too far dec angle
                    {
                    a-=da;
                    q=(2.0*a)-atanxy(cos(a),sin(a)*E);
                    x=ellipse.x+(ellipse.rx*cos(a))+(R*cos(q))-circle[i].x; x*=x;
                    y=ellipse.y+(ellipse.ry*sin(a))+(R*sin(q))-circle[i].y; y*=y; x+=y;
                    if (x<=l) break;
                    }
                else if (x<l) for (;;)  // if too short inc angle
                    {
                    a+=da;
                    q=(2.0*a)-atanxy(cos(a),sin(a)*E);
                    x=ellipse.x+(ellipse.rx*cos(a))+(R*cos(q))-circle[i].x; x*=x;
                    y=ellipse.y+(ellipse.ry*sin(a))+(R*sin(q))-circle[i].y; y*=y; x+=y;
                    if (x>=l) break;
                    }
                else break;
                }
            }
        // check if last circle is joined as it should be
        x=circle[N-1].x-circle[0].x; x*=x;
        y=circle[N-1].y-circle[0].y; y*=y; x+=y;
        if (dm>0.0) { if (x>=l) break; }
        else        { if (x<=l) break; }
        m+=dm;
        }
    }

Well I know its a little messy code so here is some info:

  1. first it try to set as close ellipse rx,ry axises as possible

    ellipse length should be about N*R*2 which is polygon length of lines between circle centers

  2. try to compose circles so they are touching each other and the ellipse

    I use iteration of ellipse angle for that. Problem is that circles do not touch the ellipse in their position angle thats why there is q variable ... to compensate around ellipse normal. Look for yellowish-golden lines in image

  3. after placing circles check if the last one is touching the first

    if not interpolate the size of ellipse actually it scales the rx,ry by m variable up or down

  4. you can adjust accuracy

    by change of the j,k fors and/or change of dm,da scaling factors

  5. input parameter E should be at least 0.5 and max 1.0

    if not then there is high probability of misplacing circles because on very eccentric ellipses is not possible to fit circles (if N is too low). Ideal setting is 0.7<=E<=1.0 closser to 1 the safer the algorithm is

  6. atanxy(dx,dy) is the same as `atan(dy/dx)

    but it handles all 4 quadrants like atan2(dy,dx) by sign analysis of dx,dy

Ellipse + circles

Hope it helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CaptureElement as an ellipse shape

From Dev

How to fill an ellipse shape?

From Dev

Issue with ellipse angle calculation and point calculation

From Dev

How to create ellipse shape geometry

From Dev

ellipse midpoint algorithm counterclockwise version

From Dev

Improving my Ellipse Fitting Algorithm

From Dev

ellipse midpoint algorithm counterclockwise version

From Dev

ggplot2 confidence ellipse shape incomplete

From Dev

Time complexity calculation of algorithm

From Dev

java algorithm calculation of precision

From Dev

Algorithm Recursive Formula Calculation

From Dev

CRC checksum calculation algorithm

From Dev

Efficient algorithm for matrix calculation

From Dev

CPU statistics calculation algorithm

From Dev

Optimizing shape detection algorithm

From Dev

2D transforms in ellipse drawing algorithm

From Dev

Message "‘CV_SHAPE_ELLIPSE’ was not declared in this scope" in OpenCV 3

From Dev

Graphviz - Python : Making node shape into double ellipse with Graphviz

From Dev

Time complexity calculation for my algorithm

From Dev

Fermat Algorithm for prime factors calculation

From Dev

TFLearn regression, shape incompatibility in loss calculation

From Dev

How to find centroid of a ellipse in my camshift tracking algorithm?

From Dev

Most efficient algorithm to find integer points within an ellipse

From Dev

Fastest algorithm for all whole lat/lng intersections in a rotated ellipse?

From Java

Understanding Time complexity calculation for Dijkstra Algorithm

From Dev

Need an algorithm written for delay time calculation

From Dev

trouble in calculation the right algorithm in javascript to draw an array

From Dev

Porting CRC Calculation algorithm from C to Java

From Dev

C# Windows form algorithm calculation

Related Related

  1. 1

    CaptureElement as an ellipse shape

  2. 2

    How to fill an ellipse shape?

  3. 3

    Issue with ellipse angle calculation and point calculation

  4. 4

    How to create ellipse shape geometry

  5. 5

    ellipse midpoint algorithm counterclockwise version

  6. 6

    Improving my Ellipse Fitting Algorithm

  7. 7

    ellipse midpoint algorithm counterclockwise version

  8. 8

    ggplot2 confidence ellipse shape incomplete

  9. 9

    Time complexity calculation of algorithm

  10. 10

    java algorithm calculation of precision

  11. 11

    Algorithm Recursive Formula Calculation

  12. 12

    CRC checksum calculation algorithm

  13. 13

    Efficient algorithm for matrix calculation

  14. 14

    CPU statistics calculation algorithm

  15. 15

    Optimizing shape detection algorithm

  16. 16

    2D transforms in ellipse drawing algorithm

  17. 17

    Message "‘CV_SHAPE_ELLIPSE’ was not declared in this scope" in OpenCV 3

  18. 18

    Graphviz - Python : Making node shape into double ellipse with Graphviz

  19. 19

    Time complexity calculation for my algorithm

  20. 20

    Fermat Algorithm for prime factors calculation

  21. 21

    TFLearn regression, shape incompatibility in loss calculation

  22. 22

    How to find centroid of a ellipse in my camshift tracking algorithm?

  23. 23

    Most efficient algorithm to find integer points within an ellipse

  24. 24

    Fastest algorithm for all whole lat/lng intersections in a rotated ellipse?

  25. 25

    Understanding Time complexity calculation for Dijkstra Algorithm

  26. 26

    Need an algorithm written for delay time calculation

  27. 27

    trouble in calculation the right algorithm in javascript to draw an array

  28. 28

    Porting CRC Calculation algorithm from C to Java

  29. 29

    C# Windows form algorithm calculation

HotTag

Archive