0

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...

Megidd
  • 7,089
  • 6
  • 65
  • 142
  • Why do you need to pack different indices into a single value? Use a `struct`: `type Tehtrahedron struct { Corner int; Edges [3]int }` – icza May 09 '23 at 11:47
  • @icza But my 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`. – Megidd May 09 '23 at 11:50
  • 2
    Then use a slice for each: `type Tehtrahedron struct { Corners, Edges []int }` – icza May 09 '23 at 11:52
  • @icza Looks good. What would be a clean & robust way to make sure that the sum of the length of two slices is always `4`? – Megidd May 09 '23 at 11:54
  • 2
    Create a constructor like `NewTehtrahedron()` function, passing `Corners, Edges`, which should check the sum, and either panic (if reasonable) or return an `error`. – icza May 09 '23 at 12:02
  • @icza Wow! I forgot one major thing, the order of indices matters :( – Megidd May 09 '23 at 12:08
  • 2
    How are you using `tehtrahedron` later on? What code do you want to be simple and readable? – icza May 09 '23 at 12:26
  • @icza This is part of a quite large repository. Let me think about how to explain better... – Megidd May 09 '23 at 12:28
  • "A tetrahedron doesn't consist of 1 corner and 3 edges all the time." Can you give an example of a tetrahedron that isn't uniquely defined if given one corner and three (distinct) edges from that corner? – Volker May 09 '23 at 14:29
  • @Volker As an example, a tetrahedron can be composed by 4 corners of a 3D cube without any edge involved. For example, a 3D cube can be cut into 6 tetrahedra by just using the corners, i.e. no edge is involved. Like this: https://puzzling.stackexchange.com/a/12897/68532 – Megidd May 09 '23 at 15:02
  • Of course, but that's not what I'm asking. If you are given one corner and three edges from that corner than you uniquely defined a tetrahedron. Do you need a way to define a tetrahedron by _any_ combination of corners and edges? Why do you think about edges anyway? Just convert edges to corners. If you tetrahedron spec of corners, edges and combinations thereof yields 4 different corners its valid and you have a canonical representation of you tetrahedron. You are probably overcomplication the problem by insisting on edges. – Volker May 09 '23 at 15:48
  • @Volker Yes, definitely. I need to be able to define a tetrahedron by *any* combination of corners and edges possible. There are many possible cases, I will have to consider all of them. That's the source of complexity for me. – Megidd May 09 '23 at 16:18
  • @Volker Let me try to define the math problem that I'm trying to solve. My input is a 3D cube cut by any number of 3D planes. Each edge can be cut only once. Then, I should convert the spaces of the 3D cube - bound by 3D planes - into a collection of tetrahedra. My outputs are the tetrahedra. – Megidd May 09 '23 at 16:26
  • Okay, but either I misunderstand your problem or this is mathematically trivial as the result is fixed and doesn't depend on the input. Eight points (where no more than 4 lie in the same plane) define 70 tetrahedrons, just iterate over the points (your cube) and chose 4. Edges do not play any _useful_ role in the problem you stated. – Volker May 09 '23 at 16:49
  • @Volker Let me think about it and get back :) – Megidd May 09 '23 at 16:55

1 Answers1

0

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.

Megidd
  • 7,089
  • 6
  • 65
  • 142