示例#1
0
        public static Polygon Ellipse(Point center, double xRadius, double yRadius)
        {
            int precision = (int)GMath.Ceiling(GMath.Pi * GMath.Abs(xRadius + yRadius));

            if (precision <= 0)
            {
                return(new Polygon(new[] { center }));
            }
            double dt = GMath.Tau / precision;
            double c = GMath.Cos(dt), s = GMath.Sin(dt);

            double x = 1, y = 0, tmp;

            var pts = new Point[precision];

            for (int i = 0; i < precision; i++)
            {
                pts[i] = new Point(center.X + x * xRadius, center.Y + y * yRadius);

                tmp = x;
                x   = c * x - s * y;
                y   = s * tmp + c * y;
            }

            return(new Polygon(pts));
        }
示例#2
0
        public static Polygon Circle(Point center, double radius)
        {
            if (radius == 0)
            {
                return(new Polygon(new[] { center }));
            }

            int precision = (int)GMath.Ceiling(GMath.Tau * GMath.Abs(radius));

            if (precision < 2)
            {
                precision = 2;
            }

            return(Regular(precision, radius, center));
        }