在Angus的Clipper与其他库的基准测试中,他有一个多边形区域计算方法 . 我用它并修改了他的椭圆方法 . 结果如下:
void Ellipse2Poly(double theta, double A1, double B1, double H1, double K1, Poly& p)
{
const double pi = 3.1415926535898, tolerance = 0.125;
const int n = 30;
double step = pi/(double)n;
double a = A1; // Long semi-axis length
double b = B1; // short semi-axis length
double xc = H1; // current X position
double yc = K1; // current Y position
double sintheta = sin(theta);
double costheta = cos(theta);
double t = 0;
p.resize(2*n+1);
for (int i = 0; i < 2*n+1; i++)
{
p[i].x = xc + a*cos(t)*costheta - b*sin(t)*sintheta;
p[i].y = yc + a*cos(t)*sintheta + b*sin(t)*costheta;
t += step;
}
}