首页 > 解决方案 > 使用这个类创建一个圈子

问题描述

我在搞一个 MMORPG 游戏,我需要使用这个类创建一个圈子

我需要使用它的方式如下:

ExServerPrimitive ex = new ExServerPrimitive("Circle", 
 object.getLocation());
 // Create the circle using the method addLine like  ex.addLine(Color.RED, x, y, z); 

我尝试查看如何使用线条创建圆圈的示例,但我失败了,主要是因为我不擅长数学。任何帮助将不胜感激。

非常感谢

标签: geometry

解决方案


我的数学可能有点生疏,但它应该看起来像这样。

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;
}

推荐阅读