我想在C ++中围绕其中心旋转多边形。
我希望围绕其中心旋转多边形,而不是旋转的结果。
但结果是旋转多边形。
我的代码如下:
double pi = atan(1) * 4;
double radian = 180 / pi;
int N = 1;
double angle = radian * (N % 10);
double Sin = sin(angle);
double Cos = cos(angle);
int Radius = 60;
int xC = 256;
int yC = 256;
for (int i = 0; i < 10; i++) {
for (int k = 0; k < 10; k++) {
Draw1Dot(256+i, 256+k, 0.2f, 0.7f, 0.7f);
}
}
time_t start, end;
DrawCircle(Radius, xC, yC, Sin, Cos);
do {
time(&start);
end = start;
while (end - start != 3) {
void clear();
N++;
time(&end);
DrawCircle(Radius, xC, yC, Sin, Cos);
}
} while (N == 10);
我的目标是随着N增加,圆圈围绕其中心旋转。
我使用了Sleep()函数来获得平滑的移动效果。
-edit -
有人希望看到DrawCircle()函数,我听了。
这个功能只是绘制圆圈,所以我不写这个。
绘图代码如下:
int Check = 1 - Radius;
int x = 0;
int y = Radius;
//circle edge drawing code
Draw1Dot(xC + x + (Radius * Cos), yC + y + (Radius * Sin), 1.f, 1.f, 1.f); //1
Draw1Dot(yC + y + (Radius * Cos), xC + x + (Radius * Sin), 1.f, 1.f, 1.f); //2
Draw1Dot(yC + y + (Radius * Cos), xC - x + (Radius * Sin), 1.f, 1.f, 1.f); //3
Draw1Dot(xC + x + (Radius * Cos), yC - y + (Radius * Sin), 1.f, 1.f, 1.f); //4
Draw1Dot(xC - x + (Radius * Cos), yC - y + (Radius * Sin), 1.f, 1.f, 1.f); //5
Draw1Dot(yC - y + (Radius * Cos), xC - x + (Radius * Sin), 1.f, 1.f, 1.f); //6
Draw1Dot(yC - y + (Radius * Cos), xC + x + (Radius * Sin), 1.f, 1.f, 1.f); //7
Draw1Dot(xC - x + (Radius * Cos), yC + y + (Radius * Sin), 1.f, 1.f, 1.f); //8
while (x <= y) {
x++;
if (Check < 0)
Check += (2 * x) + 1;
else {
Check += 2 * (x - y) + 1;
y--;
}
Draw1Dot(xC + x + (Radius * Cos), yC + y + (Radius * Sin), 1.f, 1.f, 1.f); //1
Draw1Dot(yC + y + (Radius * Cos), xC + x + (Radius * Sin), 1.f, 1.f, 1.f); //2
Draw1Dot(yC + y + (Radius * Cos), xC - x + (Radius * Sin), 1.f, 1.f, 1.f); //3
Draw1Dot(xC + x + (Radius * Cos), yC - y + (Radius * Sin), 1.f, 1.f, 1.f); //4
Draw1Dot(xC - x + (Radius * Cos), yC - y + (Radius * Sin), 1.f, 1.f, 1.f); //5
Draw1Dot(yC - y + (Radius * Cos), xC - x + (Radius * Sin), 1.f, 1.f, 1.f); //6
Draw1Dot(yC - y + (Radius * Cos), xC + x + (Radius * Sin), 1.f, 1.f, 1.f); //7
Draw1Dot(xC - x + (Radius * Cos), yC + y + (Radius * Sin), 1.f, 1.f, 1.f); //8
}
//Circle filling code
for (int y = -Radius; y <= Radius; y++) {
for (int x = -Radius; x <= Radius; x++) {
if (x*x + y*y <= Radius*Radius)
Draw1Dot(xC + x + Radius*Cos, yC + y + Radius*Sin, 1.f, 1.f, 1.f);
}
}
答案 0 :(得分:0)
您不会改变绘制形状的角度。
int Radius = 60;
int xC = 256;
int yC = 256;
double angle = START_ANGLE;
time_t start, end;
time(&start);
while (angle < MAX_ANGLE) {
clear();
time(&end);
angle = ANGULAR_SPEED * (end - start);
DrawCircle(Radius, xC, yC, sin(angle), cos(angle));
}
您需要为START_ANGLE,MAX_ANGLE和ANGULAR_SPEED定义一些值