合并两个索引编号

huangapple go评论83阅读模式
英文:

Combining two index numberings

问题

背景

一个3D立方体有12条边和8个角落。

角落索引

8个角落已经从07进行了索引。

      7---------6
     /|        /|
    / |       / |
   4---------5  |
   |  |      |  |
   |  3------|--2
   | /       | /
   |/        |/
   0---------1

边缘索引

11条边已经从011进行了索引。

// 这些是边缘的角落对:
var mcPairTable = [12][2]int{
	{0, 1}, // 边缘 0
	{1, 2}, // 边缘 1
	{2, 3}, // 边缘 2
	{3, 0}, // 边缘 3
	{4, 5}, // 边缘 4
	{5, 6}, // 边缘 5
	{6, 7}, // 边缘 6
	{7, 4}, // 边缘 7
	{0, 4}, // 边缘 8
	{1, 5}, // 边缘 9
	{2, 6}, // 边缘 10
	{3, 7}, // 边缘 11
}

组合两个索引编号

我想在3D立方体内部绘制四面体。为了描述一个四面体,我可以使用边缘和角落的索引。例如,一个四面体由角落0,边缘0,边缘3和边缘8组成。

问题

我的问题是索引编号。我不知道如何将边缘的索引与角落的索引结合起来。我有两个选项可以进行索引编号。

选项1:字符串

一种选项是使用字符串来组成一个四面体。例如,我使用C前缀表示角落索引,使用E前缀表示边缘索引:

var tetrahedron = [4]string{"C0", "E0", "E3", "E8"}

但是使用字符串不像简单的整数索引那样容易。

选项2:移动索引

另一个选项是保持边缘的索引从011,但是移动角落的索引。因此,角落的索引将从0+127+12,即从1219进行索引。使用这个选项,同样的四面体将是这样的:

var tetrahedron = [4]int{0+12, 0, 3, 8}

或者:

var tetrahedron = [4]int{12, 0, 3, 8}

但是这个选项会破坏我的其他代码,并且会使我的代码难以阅读。

注意事项

  1. 一个四面体不总是由1个角落和3条边组成。组合是任意的。但是角落和边缘的总数始终为4
  2. 四面体的索引顺序很重要。

问题

有没有一种方便的方法来保持边缘和角落的原始索引编号?
同时能够通过边缘和角落的索引表示四面体吗?

寻找一些想法...

英文:

Background

A 3D cube has 12 edges and 8 corners.

Corner indexing

8 corners are already indexed 0 to 7.

      7---------6
     /|        /|
    / |       / |
   4---------5  |
   |  |      |  |
   |  3------|--2
   | /       | /
   |/        |/
   0---------1

Edge indexing

11 edges are already indexed from 0 to 11.

// These are the corner pairs for the edges:
var mcPairTable = [12][2]int{
	{0, 1}, // Edge 0
	{1, 2}, // Edge 1
	{2, 3}, // Edge 2
	{3, 0}, // Edge 3
	{4, 5}, // Edge 4
	{5, 6}, // Edge 5
	{6, 7}, // Edge 6
	{7, 4}, // Edge 7
	{0, 4}, // Edge 8
	{1, 5}, // Edge 9
	{2, 6}, // Edge 10
	{3, 7}, // Edge 11
}

Combining two index numberings

I want to draw tetrahedra inside the 3D cube. To describe a tetrahedra, I can use the indices of edges and corners. For example, a tetrahedron would consist of Corner 0, Edge 0, Edge 3, and Edge 8.

Problem

My problem is index numbering. I don't know how to combine the index of edges with those of corners. I have two options for index numbering.

Option 1: string

One option is to use strings to compose a tetrahedron. For example I use the C prefix for corner indices and the E prefix for edge indices:

var tehtrahedron = [4]string{"C0", "E0", "E3", "E8"}

But working with strings is not as easy as simple integer indices.

Option 2: shifting indices

The other option is to keep the index from 0 to 11 for edges, but shift the index for corners. So, corners would be indexed from 0+12 to 7+12 i.e. from 12 to 19. Using this option, the same tetrahedron would be like:

var tehtrahedron = [4]int{0+12, 0, 3, 8}

Or:

var tehtrahedron = [4]int{12, 0, 3, 8}

But this option would mess up the rest of my code and would make my code hard to read.

Notes

  1. A tetrahedron doesn't consist of 1 corner and 3 edges all the time. The combination is arbitrary. But the total count of corners and edges is always 4.
  2. The order of indices for tetrahedron matters.

Question

Is there a convenient way to keep the original index numbering for edges and corners?
And at the same time be able to represent the tetrahedra by index of edges and corners?

Looking for some ideas...

答案1

得分: 0

最终,我选择了移动索引的选项。将索引011用于边缘,将索引1219用于角落。

我这样做是因为边缘和角落的组合是任意的。此外,索引的顺序是关键的。

英文:

Eventually I ended up with the option of shifting indices. Index 0 to 11 for edges and index 12 to 19 for corners.

I have to do so since the combination of edges and corners is arbitrary. Also, the order of indices is critical.

huangapple
  • 本文由 发表于 2023年5月9日 19:40:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76208933.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定