2
$\begingroup$

how can one map barycentric indices to a single integer?

e.g.

Edit: added correct image

enter image description here

$\endgroup$
5
  • $\begingroup$ This doesn't really look much like either a puzzle or a question about puzzles. Also, it looks to me as if your barycentric coordinates are for points and you are looking to turn them into index numbers for triangles, which is a bit odd. $\endgroup$
    – Gareth McCaughan
    Commented Jul 11, 2017 at 13:12
  • $\begingroup$ You are right. Still, it is a puzzle to me :) And I thought here would be a good place to ask. It is needed for triangle identification in raytracing. $\endgroup$
    – Joe
    Commented Jul 11, 2017 at 13:22
  • $\begingroup$ Perhaps math.stackexchange.com might be a better home for this question? Or cs.stackexchange.com which I know has a computational-geometry tag? Anyway, I answered it anyway because why not :-). $\endgroup$
    – Gareth McCaughan
    Commented Jul 11, 2017 at 13:35
  • $\begingroup$ if you created two more triangles, you would have 27 in total, hence ternary. you've listed 1,2,3,4,6,9,10,12,18, which doesn't mean much. perhaps if you found the other two triangles it might make more sense. $\endgroup$
    – JMP
    Commented Jul 11, 2017 at 15:09
  • $\begingroup$ mind you it's still a maths problem :) $\endgroup$
    – JMP
    Commented Jul 11, 2017 at 15:13

1 Answer 1

3
$\begingroup$

[Note: OP has revised the question with a slightly different barycentric indexing scheme, which makes the following no longer quite right. I'll fix it up in a minute.]

Number the rows of triangles from 0. If the big triangle has $n$ little triangles on each side, then row $k$ contains the triangles whose reference points have barycentric coords $(n-1-k,b,c)$ for some $b,c$. And it begins with triangle number $k^2$. (Rows have 1,3,5,... triangles; sums of odd numbers are squares.)

Then the (0-based) position within its row of the triangle with barycentric indices $(a,b,c)$ is $2c+\varepsilon$ where $\varepsilon$ is 0 for upward-pointing triangles and 1 for downward-pointing ones; we can distinguish these because the sum of all the barycentric indices is $n-1$ for upward triangles and $n-2$ for downward. In other words, $\varepsilon=n-1-(a+b+c)$.

Therefore, the triangle with barycentric indices $(a,b,c)$ is in row $n-1-a$ which begins with triangle $(n-1-a)^2$; within that row its (0-based) position is $2c+n-1-(a+b+c)=n-1-a-b+c$; so its index number is $(n-1-a)^2+n-1-a-b+c$.

Let's do a spot check. Triangle 7 has $(a,b,c)=(0,0,1)$ and $n-1=2$. So the index number is $(2-0)^2+2-0-0+1$ which is indeed 7. Looks like it works.

(Remark: $n-1$ is probably a nicer parameter to work with than $n$ itself.)

$\endgroup$
3
  • $\begingroup$ @Joe If my answer is exactly what you wanted, you should probably indicate that by clicking on the checkmark icon to its left... $\endgroup$
    – Gareth McCaughan
    Commented Jul 12, 2017 at 2:18
  • $\begingroup$ ... Oh, wait, you probably can't because the question is on hold. Sorry. $\endgroup$
    – Gareth McCaughan
    Commented Jul 12, 2017 at 2:19
  • $\begingroup$ Sorry, forgot, I just made an invisible upvote :) $\endgroup$
    – Joe
    Commented Jul 12, 2017 at 5:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.