geometry - 使用这个类创建一个圈子
问题描述
我在搞一个 MMORPG 游戏,我需要使用这个类创建一个圈子
我需要使用它的方式如下:
ExServerPrimitive ex = new ExServerPrimitive("Circle",
object.getLocation());
// Create the circle using the method addLine like ex.addLine(Color.RED, x, y, z);
我尝试查看如何使用线条创建圆圈的示例,但我失败了,主要是因为我不擅长数学。任何帮助将不胜感激。
非常感谢
解决方案
我的数学可能有点生疏,但它应该看起来像这样。
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;
}
推荐阅读
- chisel - 凿子:When-otherwise 子句在函数定义中不起作用
- java - 在android中创建像glide和picasso这样的类结构
- ansible - ansible 的 maven_artifact comman 在 Rundeck 中不起作用
- react-native - 如何在 React Native 中复制警告消息
- reactjs - 小时候如何使用 React Portal 发送图像?
- json - 如何从 POSTMAN 发送包含 xml 值的 Json?
- pyspark - 从 pyspark 中的数据帧中随机抽样
- android - Arraylist 从片段传递到活动
- bash - 用 bash 计算列数
- android-fragments - 片段已添加问题,当使用带有底部导航栏 android 的导航时