我正在玩MMORPG游戏,我需要使用此class
创建一个圆圈我需要使用它的方式如下:
ExServerPrimitive ex = new ExServerPrimitive("Circle",
object.getLocation());
// Create the circle using the method addLine like ex.addLine(Color.RED, x, y, z);
我尝试查看如何使用直线创建圆的示例,但我失败了,主要是因为我对数学不太擅长。任何帮助将不胜感激。
非常感谢
答案 0 :(得分:1)
我可能对数学有点生疏,但看起来应该像这样。
int centerX = 0;
int centerY = 0;
int radius = 10;
int segments = 10;
x1 = centerX - radius;
y1 = centerY;
int x2, y2;
int z1 = 0;
int z2 = 0;
for(int l = 1; l<=segments; l++)
{
int angle = (360 / segments) * l;
dx = cos(angle) * radius;
dy = sin(angle) * radius;
x2 = centerX + dx;
y2 = centerY + dy;
ex.addLine(Color.RED, x1, y1, z1, x2, y2, z2);
x1 = x2;
y1 = y2;
}