【发布时间】:2015-03-19 04:57:12
【问题描述】:
好的,所以我有一个多边形(简单但凹形),我试图将它切割成三角形,使其与另一个多边形相撞。
我知道我的多边形是凹的,所以我决定使用 LibGDX EarClippingTriangulator 将它切割成三角形。
所以,通过这段代码,我得到了我的三角形顶点:
public void triangulate()
{
Vector<float[]> trianglesVertices = new Vector<float[]>();
ShortArray pointsCoords = new ShortArray();
EarClippingTriangulator triangulator = new EarClippingTriangulator();
// Cut in triangles
pointsCoords = triangulator.computeTriangles(this.getTransformedVertices());
// Make triangles
for (int i = 0; i < pointsCoords.size / 6; i++)
{
trianglesVertices.add(new float[] {
pointsCoords.get(i), pointsCoords.get(i+1),
pointsCoords.get(i+2), pointsCoords.get(i+3),
pointsCoords.get(i+4), pointsCoords.get(i+5),
});
Polygon triangle = new Polygon(trianglesVertices.get(i));
triangles.add(triangle);
}
System.out.printf("Triangulation made %d triangles.\n", pointsCoords.size / 6);
}
但是当我尝试绘制我刚刚制作的那些三角形时, 他们只是堆叠在 0,0 坐标中.. 而且,所有三角形看起来几乎相同是否正常,我的意思是它们都具有相同的方向?
我没有找到太多关于这个用于 libgdx 的 trangulation 的信息 你能帮忙吗?
(对不起我的英语我是法国人,对不起没有照片,我在这里太年轻了)
编辑:这是我的多边形(逆时针)
hitbox.setVertices(new float[]{
this.getX() + 13, this.getY() - 60,
this.getX() + 16, this.getY() - 74,
this.getX() + 39, this.getY() - 74,
this.getX() + 45, this.getY() - 105,
this.getX() + 81, this.getY() - 105,
this.getX() + 88, this.getY() - 74,
this.getX() + 108, this.getY() - 74,
this.getX() + 114, this.getY() - 61,
this.getX() + 106, this.getY() - 30, // Top right
this.getX() + 101, this.getY() - 29,
this.getX() + 101, this.getY() - 57,
this.getX() + 83, this.getY() - 62,
this.getX() + 75, this.getY() - 50,
this.getX() + 65, this.getY() - 4, // Top mid
this.getX() + 62, this.getY() - 4, // Top mid
this.getX() + 52, this.getY() - 50,
this.getX() + 44, this.getY() - 62,
this.getX() + 25, this.getY() - 56,
this.getX() + 25, this.getY() - 30,
this.getX() + 19, this.getY() - 30, // Top left
});
EDIT2:现在我有足够的点来向您展示多边形了
【问题讨论】:
-
你能带上你遇到问题的多边形吗?
-
我只是添加它,其实它是一艘船
标签: libgdx polygon triangulation convex concave