1

行进立方体三角表是如何生成的?我知道,我可以只使用预先计算的一个,但我对如何生成表格很感兴趣。

似乎原始作者通过对纸上的所有内容进行三角测量来生成它,但是有没有一种方法可以在代码中生成它?

边缘表是直截了当的,但我看不到是否有一种简单的方法可以获得三角形表,即使忽略不明确的情况也是如此。

4

3 回答 3

0

这是一种方法:

从顶点和边缘点开始。现在,如果一个顶点打开,则将三个边缘点与该顶点相邻。对每个顶点执行此操作。

现在,注意连接顶点的边。删除位于它们上面的边缘点。

利用这些边缘点制作一个三角形阵列。

这样,您可以使用循环 256 次的 for 循环来制作三角表,实际上,使用这种方法,您甚至可能不需要一个。

为了测试它:

尝试使用我告诉你的方法。有用。不过只有一件事,我在测试它时因为它是如何绘制的而感到困惑。总之,享受吧!:)

编辑:这样你可以使用任何方式来渲染三角形。人们使用不同的三角表。使用这种方法,您不必弄清楚边缘点的编号是什么。您可以按照自己的方式使用它,这样您就不必浪费时间弄清楚了。

于 2018-08-21T12:32:30.770 回答
0

这是算法的原始解释:http: //paulbourke.net/geometry/polygonise/

于 2017-06-27T06:34:44.257 回答
-2

Another Solution (DONT LOOK AT THIS UNTIL I TELL YOU TO DO SO) (OR ELSE YOU'LL SEE MY UNFINISHED MESS BECAUSE I HAVE NO TIME TO FINISH IT)

I won't really be citing code.

The Marching Cube Triangle List starts from a cube.

If you have a cube, or can make one, I would advice you to use one, just for convenience. Neatly number its corners and edges using a pen or a marker. Please don't count them irregularly. Make the counting "programmable".

A cube has 8 corners. Let's imaging each corner as a light bulb. So the triangle list generates triangles for every combination of on and off light bulbs. That is, 256 combinations. ( (2 bulb conditions)^(8 bulbs) = 256 combinations) But how is a triangle list generated?

For every combination, we have a unique cube. Let's start with a combination like this

 /7.on-----8.off
/ |           /|
3.off----4.on/ |
| 5.on ------| 6.off
| /          | /
|/           |/
1.on------2.off

We can make a list of corners or bulbs. bulb 1, bulb 2, bulb 3 - bulb 8 And then tell if they're on or off on, off, off... off The way you number your points really depends on what you want. Though I would recommend an organized way. There are 40,320 combinations of point orders. For this example I'm using the order I'm used to.

We could turn this list of bulb states into a binary number. Off means 0, on means 1. 10011010 in binary = 154th index of table

Probably you know all of this :P

2. Create a 12-element array of edge points. For the newbies (no offense rlly): edge points -> points lying on the edge.

int[] edgePoints = new int[12] {0,0,0,0,0,0,0,0,0,0,0,0} //12 elements

Then we enable the edge points. For every corner point, enable its adjacent edge points. If this iteration is done, check if a point has been enabled more than 1 time. If it has, disable it. If it hasn't been enabled, it's disabled.

Now you have your valid edge points. Store in an array or list. Now let's make the triangles.

Here are some arrays we can use.

List<int> validVertexIndices = new List<int>(); //add the valids
List<int> usedVertices = new List<int>();
List<int> oldVertices = new List<int>();
List<int[]> usedTris = new List<int[]>();

Let's start by making one triangle. The program doesn't really know how to connect the dots. (to make triangles) So, let's start with a random point. (Best start with the lowest index)

usedVertices.Add(your random point index);

Then check the nearest point to the starting point. To do this, iterate though all of the points except the one started with. Check the distance between the starting point and every other point. (assuming the x,y,z position of each point is a perfect multiple of 0.5) (example 0, 0.5, 1.0)

If the distance between the starting point and another point is the shortest among all the other distances, then those two are the first two points of the first triangle.

usedVertices.Add(That second point to be used);

Then get the nearest point to the second point, that isn't the first or the second point. That's the third point.

usedVertices.Add(The third point);

And then you can register the triangle.

usedTris.Add(usedVertices.ToArray());
oldVertices.Add(usedVertices);
usedVertices = new List<int>();

Now for the other triangles. There are a lot of rules. You could simply repeat the process for the first triangle, except this time, you'd have to reset the iteration and change a point if it goes against the rules. You can change the first point to the next point that isn't used. Then the second point and third point if it fails.

The three main rules are: 1. Triangles shouldn't be the same as the previous triangles. 2. Triangles shouldn't intersect. There are intersection algorithms out there but I can't put them here as they are too long. 3. Check if it is covering enabled corner points. - Get the average distance of all adjacent enabled corner points and see if it is parallel and has the same direction with the normal of the current triangle.

It's complicated and might not be successful but you've got a set of rules already.

Keep on doing it until you have reached n(n-1)/2 times. You are then guranteed to have triangles. (where n = number of enabled edge points);

Then, for every triangle, create a clone so that its normal is reversed.

Then there you have it. Might not be like much so it's better to just find a source.

lol also, please do not make and train a neural network to make one xD that is just torture.

于 2019-05-08T12:41:40.317 回答