我从一个完美的圆开始,然后我需要在不丢失椭圆特征的情况下自由旋转和缩放它:
我想知道是否有一种方法可以描述仅基于余弦和正弦的椭圆。
我有这个代码:
float centerX = 100;
float centerY = 100;
float radiusX = 100;
float radiusY = 100;
float rotation = PI;
float res = 30;
for (int i = 0; i < res; i++) {
//find the point in space for the circle resolution
float angle = (float)i/res * TWO_PI;
float x = radiusX * cos(angle);
float y = -radiusY * sin(angle);
//rotate the point
float s = sin(rotation);
float c = cos(rotation);
// translate point to origin:
p->x -= centerX;
p->y -= centerY;
float xnew = p->x * c - p->y * s;
float ynew = p->x * s + p->y * c;
// translate point back
x = xnew + centerX;
y = ynew + centerY;
//apply X Y
}
此代码只能表示相同的椭圆,忽略旋转和缩放之间的关系: