3

这是一个相当补救的问题。我一直在查看 JTS DelaunayTriangulationBuilder 的文档,我不知道如何做看起来应该很简单的事情。我希望获取一系列点,对它们进行三角剖分,然后在该网格中插入随机点的 Z 值。粗略阅读如何做到这一点并不明显。有任何想法吗?

4

2 回答 2

4

加载三角剖分对象后,调用getSubdivision()它来获取三角剖分。它使用四边数据结构,稍后您将需要它。(如果您知道什么是半边或翼边表示,则更容易理解。)结果QuadEdgeSubdivision有一个方法locate,给定一个坐标,返回封闭三角形的一条边(作为四边形)。用 获取它的源顶点,用 获取它orig()的目标顶点dest()。获取另一条边,oNext()其目标顶点是第三个顶点(dPrev().origin() 也是同一个顶点)。现在您有了三个顶点,将您的测试点表示为 aVertex和 call interpolateZValue

例如:

public static double 
interpolateZ(DelaunayTriangulationBuilder triangulation,
             Coordinate coordinate) {
    QuadEdgeSubdivision quadEdgeSubdivision = triangulation.getSubdivision();
    QuadEdge edge = quadEdgeSubdivision.locate(coordinate);
    return new Vertex(coordinate.x, coordinate.y)
            .interpolateZValue(edge.orig(), edge.dest(), edge.oNext().dest());
}

不过,你是对的。通过阅读他们的 API 如何做到这一点并不明显。

于 2012-11-20T02:24:08.577 回答
2

I'm not familiar with JTS DelauneyTriangulationBuilder, but it sounds like you have a collection of points (x,y,z), and you are submitting the 2D (x,y) pairs to the triangulator. This gives you a planar triangulation of the (x,y) points, but also a mesh who's vertices are the original (x,y,z) points.

Once you have a triangulation, you wish to find the point (p,q,r) on the mesh that corresponds to the planar point (p,q). To do so, find the triangle T of the Delauney triangulation that contains (p,q). Find the barycentric coordinates of (p,q) relative to T, and use these to compute a weighted average r of the z values corresponding to the vertices of T. That weighted average is the Z value you're looking for. In other words, (p,q,r) is on the mesh.

于 2012-11-05T19:59:49.393 回答