算法计算形状(椭圆)椭圆、算法、形状

2023-09-11 03:49:41 作者:风决定要走,云怎么挽留

我有n个圈子,必须完全围绕椭圆如图所示图片浏览:

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

在这张照片我需要找出周围的椭圆每个圆圈的位置,也能计算,这将完全适合那些周围的圆圈内的椭圆。

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.

推荐答案

OK,因为我知道你知道圈子R0和他们的数N的公共半径,想知道里面的椭圆的参数和一切的位置。

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;

有关椭圆的一个全新的挑战(我花了两个小时才找到所有的怪癖了)

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;
        }
    }

嗯,我知道它有点乱code所以这里是一些信息:

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

首先,它试图将其设置为接近椭圆RX,RY轴系越好 在椭圆形的长度应为N * R * 2,它是圆的圆心之间的线面长度 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 在我使用椭圆角的迭代为 的问题是,界不要触摸椭圆的位置角 这就是为什么为q变... 来弥补各地椭圆正常 外观图像黄金行 如果不插椭圆的大小 在实际上它扩展了RX,RY由M变量向上或向下 在第j的变化,K维权 和/或DM的变化,大的比例系数 如果没有,那么有乱放界的高概率 因为很偏心椭圆不可能适合圆(如果N太低) 在理想的环境是0.7&LT; = E&LT; = 1.0 closser 1更安全的算法是 ,但它处理所有的4个象限 将DX的迹象分析,DY

希望它可以帮助