Me *_*ain 13
使用罪和cos
for (double t = 0; t < 2*Pi; t += 0.01) {
x = R*cos(t) + x_0;
y = R*sin(t) + y_0;
}
Run Code Online (Sandbox Code Playgroud)
哪里:
小智 7
或者以角度而不是弧度......
#include <math.h>
void Circle(float center_x, float center_y, float radius)
{
float point_x, point_y;
int ctr;
for (ctr = 0; ctr < 360; ctr += 1)
{
point_x = radius * cos(ctr * 3.1415926f / 180.0f) + center_x;
point_y = radius * cos(ctr * 3.1415926f / 180.0f) + center_y;
}
}
Run Code Online (Sandbox Code Playgroud)
围绕中心点绘制一个圆,每次1度.您可以按任意数量递增ctr来调整步长.
你可以使用极坐标:
X = R * cos (phi) + center_X
Y = R * sin (phi) + center_Y
Run Code Online (Sandbox Code Playgroud)
并改变循环中的phi.