如何获得六角形的对角线? [英] How to get the diagonals of a hexagon?

查看:159
本文介绍了如何获得六角形的对角线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  A,B,C 
D,E,F,G
H,I,J,K,L
M,N,O,P
Q,R,S

,我想将对角线约束到一定的数值​​,即:

blockquote
A + D + H = B + E + I + M = ... = L + P + S = CONST_SUM






我想通过计算每个级别的跳数来展开列表并试图找出一些数学公式来获得正确的元素。到目前为止,我只有这样:

$ $ p $ $ code矩阵([[1,2,3],[4,5,6, 7] [8,9,10,11,12],[13,14,15,16],[17,18,19])。

检查(M): -
矩阵(M),
变平(M,L),
check_sum(L,1)。

然而,数学方法在文章中似乎并不顺利。任何想法? / p>




编辑

I无法计算出数学规则(每个对角线的跳数),也许还有另一种方法,我应该遵循,而不是平坦的方法... ...

解决方案

C 。 。
D,E,F,G。
H,I,J,K,L
。 M,N,O,P
。 。 Q,R,S

然后一种对角线会有固定的 x (列),另一个固定的 y 条目(行)和第三个固定的 x - y )。如果你把它弄平,你必须以某种方式代表围绕着形状的空单元,并且在迭代时将它们加密,或者首先将它们从迭代中排除。您需要额外的内存支付更简单的公式。


The shape is like this:

  A,B,C
 D,E,F,G
H,I,J,K,L
 M,N,O,P
  Q,R,S

and I want to constraint the diagonals to a certain sum, i.e.:

A+D+H = B+E+I+M = ... = L+P+S = CONST_SUM


I thought of flattening the list and trying to work out some mathematical formulas to obtain the correct elements, by computing the hops at each level. So far, I have only this:

matrix([[1,2,3],[4,5,6,7][8,9,10,11,12],[13,14,15,16],[17,18,19]).

check(M) :-
    matrix(M),
    flatten(M, L),
    check_sum(L, 1).

However, the math approach doesn't seem to go well in the paper..Any ideas?


EDIT:

I couldn't work out the math rules (the hops for every diagonal), maybe there is another approach that I should follow, and not the flattening one...

解决方案

One thing you can do is write the hexagon skewed like this:

A,B,C . .
D,E,F,G .
H,I,J,K,L
. M,N,O,P
. . Q,R,S

Then one kind of diagonals will have fixed x entry ("columns"), another fixed y entry ("rows"), and a third fixed xy difference ("descending diagonals"). If you flatten this, you have to somehow represent the empty cells surrounding the shape, and either dkip them while iterating or exclude them from the iteration in the first place. You pay for the simpler formula by extra memory requirements.

这篇关于如何获得六角形的对角线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆