如何获得六角形的对角线?

编程入门 行业动态 更新时间:2024-10-24 08:24:40
本文介绍了如何获得六角形的对角线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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 x−y 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.

更多推荐

如何获得六角形的对角线?

本文发布于:2023-11-30 02:42:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对角线   如何获得

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!