当前位置:编程学习 > C#/ASP.NET >>

椭圆的排列算法

椭圆中有N个矩形,让这N个矩形排列在椭圆的做半圆上,根据矩形个数的不同,改变椭圆的高度,这个算法应该怎么写啊,请大家帮下忙 --------------------编程问答-------------------- 路过,看看 --------------------编程问答-------------------- 参考:
http://school.itzcn.com/special-spid-12.html
上面有关于这方面的信息,楼主可以看看,希望对你有所帮助。 --------------------编程问答-------------------- 帮顶。。 --------------------编程问答-------------------- 没有我要的信息,不过还是谢谢各位 --------------------编程问答-------------------- 也许我语文不够好吧
看不懂你的题目>.<
能不能画个草图说明下... --------------------编程问答-------------------- [img=http://hi.csdn.net/space-3963981-do-album-picid-484122-goto-down.html][/img]
这几个矩形均匀的排列在椭圆的左半圆上,相邻的矩形间,在Y轴上的距离相等,如果矩形的个数增加,则椭圆的高度也会跟着增高。矩形在椭圆中的排列算法如何写啊。 --------------------编程问答-------------------- 不知道为什么图片没显示出来,可以去我的相册看下图片。谢谢! --------------------编程问答-------------------- 条件不是很清楚
如果矩形形状相同,而且是刚好放进去的话
那椭圆的高可以通过方程求出来
假设矩形宽是a,高是b,间距是c,椭圆'宽'是x1,'高'是y1.

那么(a, b*N+c*(N-1)/2 )这个点在椭圆上,直接带入椭圆方程就可以得到这个椭圆的参数

椭圆参数有了那么每个矩形的位置也就可以固定了……
--------------------编程问答-------------------- 问题已经解决了,现在才贴出来,希望有遇到类似问题的朋友有一点帮助

//该项目中有输入和输出两种模块,Input是输入模块,显示在椭圆的左半圆,
            //Output是输出模块,显示在椭圆的右半圆。
            //graphWidth 当前模块的宽, graphHeight当前模块的高
            Point center = new Point(graphWidth / 2, graphHeight / 2);

            //输入/输出小方块边长
            //int sideLength = 10;

            double radiusX = (graphWidth - inOutHeight) * 0.5;
            double radiusY = (graphHeight - inOutHeight) * 0.5;

            double x = 0;
            double y = 0;

            foreach (Input ef in InputCollection)
            {
                inputIndex++;
                double inputAngle;
                if (inputCount > 1)
                {
                    inputAngle = 2 * Math.PI / (inputCount + outputCount);
                    // 位置
                    double angle = inputIndex * inputAngle / 2;
                    x = center.X - radiusX * Math.Sin(angle) - inOutHeight;
                    y = center.Y + radiusY * Math.Cos(angle) - inOutHeight;
                }
                else
                {
                    inputAngle = 2 * Math.PI / inputCount;
                    // 位置
                    double angle = inputIndex * inputAngle;
                    x = center.X - radiusX * Math.Cos(angle) - inOutHeight / 2;
                    y = center.Y - radiusY * Math.Sin(angle) - inOutHeight / 2;
                }
                ef.PositionX = x + graphLeft;
                ef.PositionY = y + graphTop;

                Canvas.SetLeft(ef, ef.PositionX);
                Canvas.SetTop(ef, ef.PositionY);
            }

            foreach (Output ef in OutputCollection)
            {
                outputIndex++;
                double outputAngle;
                if (outputCount > 1)
                {
                    outputAngle = 2 * Math.PI / (inputCount + outputCount);

                    // 位置
                    double angle = outputIndex * outputAngle / 2;
                    x = center.X + radiusX * Math.Sin(angle) - inOutHeight;
                    y = center.Y + radiusY * Math.Cos(angle) - inOutHeight;
                }
                else
                {
                    outputAngle = 2 * Math.PI / outputCount;
                    // 位置
                    double angle = outputIndex * outputAngle;
                    x = center.X + radiusX * Math.Cos(angle) - inOutHeight / 2;
                    y = center.Y + radiusY * Math.Sin(angle) - inOutHeight / 2;
                }
                ef.PositionX = x + graphLeft;
                ef.PositionY = y + graphTop;

                Canvas.SetLeft(ef, ef.PositionX);
                Canvas.SetTop(ef, ef.PositionY);
            }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,