@@ -253,6 +253,45 @@ def tri_arete_y3(x1, y1, x2, y2):
253253 retour (y1 + y2) / 2.0 + ny * h
254254
255255
256+ def _ajouter_carre_depuis_arete(p1x, p1y, p2x, p2y, larg, haut):
257+ soit dx = p2x - p1x
258+ soit dy = p2y - p1y
259+ soit lon = math.sqrt(dx * dx + dy * dy)
260+ si lon == 0 :
261+ retour 0
262+ nx = dy / lon
263+ ny = - dx / lon
264+ soit q2x = p2x + nx * lon
265+ soit q2y = p2y + ny * lon
266+ soit q3x = p1x + nx * lon
267+ soit q3y = p1y + ny * lon
268+ _ajouter_tuile_4_direct(p1x, p1y, p2x, p2y, q2x, q2y, q3x, q3y, larg, haut)
269+ retour 0
270+
271+
272+ def _ajouter_hex_depuis_arete(p1x, p1y, p2x, p2y, larg, haut):
273+ soit dx = p2x - p1x
274+ soit dy = p2y - p1y
275+ soit lon = math.sqrt(dx * dx + dy * dy)
276+ si lon == 0 :
277+ retour 0
278+ tx = dx / lon
279+ ty = dy / lon
280+ nx = dy / lon
281+ ny = - dx / lon
282+ s3 = math.sqrt(3.0 )
283+ soit h2x = p2x + lon * (tx / 2.0 + nx * (s3 / 2.0 ))
284+ soit h2y = p2y + lon * (ty / 2.0 + ny * (s3 / 2.0 ))
285+ soit h3x = p2x + lon * (nx * s3)
286+ soit h3y = p2y + lon * (ny * s3)
287+ soit h4x = p1x + lon * (nx * s3)
288+ soit h4y = p1y + lon * (ny * s3)
289+ soit h5x = p1x + lon * (- tx / 2.0 + nx * (s3 / 2.0 ))
290+ soit h5y = p1y + lon * (- ty / 2.0 + ny * (s3 / 2.0 ))
291+ _ajouter_tuile_6_direct(p1x, p1y, p2x, p2y, h2x, h2y, h3x, h3y, h4x, h4y, h5x, h5y, larg, haut)
292+ retour 0
293+
294+
256295# ── Etat global des tuiles ────────────────────────────────────
257296
258297_methode_active = 0
@@ -636,8 +675,8 @@ def _gen_triangle(larg, haut, a):
636675
637676
638677def _gen_trihex(larg, haut, a):
639- pas_x = 2.0 * (apotheme( 6 , a) + apotheme( 3 , a))
640- pas_y = math.sqrt( 3.0 ) * (apotheme( 6 , a) + apotheme( 3 , a))
678+ pas_x = 2.0 * math.sqrt( 3.0 ) * a
679+ pas_y = 3.0 * a
641680 rangs = _nb_pas_inclusifs(- pas_y, haut + pas_y, pas_y)
642681 cols = _nb_pas_inclusifs(- pas_x, larg + pas_x, pas_x)
643682 pour rang dans range(rangs):
@@ -680,28 +719,49 @@ def _gen_trihex(larg, haut, a):
680719
681720
682721def _gen_snub_trihex(larg, haut, a):
683- _gen_trihex(larg, haut, a * 0.82 )
684- at = a * 0.72
685- h = hauteur_tri(at)
686- cols = entier(math.ceil((larg + at * 2.0 ) / (at / 2.0 ))) + 2
687- rangs = entier(math.ceil((haut + h * 2.0 ) / h)) + 2
688- cnt = 0
722+ pas_x = 2.0 * math.sqrt(3.0 ) * a
723+ pas_y = 3.0 * a
724+ at = a * 0.78
725+ rangs = _nb_pas_inclusifs(- pas_y, haut + pas_y, pas_y)
726+ cols = _nb_pas_inclusifs(- pas_x, larg + pas_x, pas_x)
689727 pour rang dans range(rangs):
690- y = - h + rang * h
728+ y = - pas_y + rang * pas_y
729+ decal = (rang % 2 ) * (pas_x / 2.0 )
691730 pour col dans range(cols):
692- si cnt % 3 == 0 :
693- x = - at + col * (at / 2.0 )
694- vers_haut = 1
695- si (rang + col) % 2 != 0 :
696- vers_haut = 0
697- soit x0 = sommet_tri_x(x, at, 0 , vers_haut)
698- soit y0 = sommet_tri_y(y, at, 0 , vers_haut)
699- soit x1 = sommet_tri_x(x, at, 1 , vers_haut)
700- soit y1 = sommet_tri_y(y, at, 1 , vers_haut)
701- soit x2 = sommet_tri_x(x, at, 2 , vers_haut)
702- soit y2 = sommet_tri_y(y, at, 2 , vers_haut)
703- _ajouter_tuile_3_direct(x0, y0, x1, y1, x2, y2, larg, haut)
704- cnt = cnt + 1
731+ x = - pas_x + decal + col * pas_x
732+ soit hx0 = sommet_hex_x(x, y, a, 0 )
733+ soit hy0 = sommet_hex_y(x, y, a, 0 )
734+ soit hx1 = sommet_hex_x(x, y, a, 1 )
735+ soit hy1 = sommet_hex_y(x, y, a, 1 )
736+ soit hx2 = sommet_hex_x(x, y, a, 2 )
737+ soit hy2 = sommet_hex_y(x, y, a, 2 )
738+ soit hx3 = sommet_hex_x(x, y, a, 3 )
739+ soit hy3 = sommet_hex_y(x, y, a, 3 )
740+ soit hx4 = sommet_hex_x(x, y, a, 4 )
741+ soit hy4 = sommet_hex_y(x, y, a, 4 )
742+ soit hx5 = sommet_hex_x(x, y, a, 5 )
743+ soit hy5 = sommet_hex_y(x, y, a, 5 )
744+ _ajouter_tuile_6_direct(hx0, hy0, hx1, hy1, hx2, hy2, hx3, hy3, hx4, hy4, hx5, hy5, larg, haut)
745+ pour i dans range(6 ):
746+ pprevx = sommet_hex_x(x, y, a, (i + 5 ) % 6 )
747+ pprevy = sommet_hex_y(x, y, a, (i + 5 ) % 6 )
748+ pvx = sommet_hex_x(x, y, a, i)
749+ pvy = sommet_hex_y(x, y, a, i)
750+ pnxtx = sommet_hex_x(x, y, a, (i + 1 ) % 6 )
751+ pnxty = sommet_hex_y(x, y, a, (i + 1 ) % 6 )
752+ dx1 = pvx - pprevx
753+ dy1 = pvy - pprevy
754+ dx2 = pnxtx - pvx
755+ dy2 = pnxty - pvy
756+ lon1 = math.sqrt(dx1 * dx1 + dy1 * dy1)
757+ lon2 = math.sqrt(dx2 * dx2 + dy2 * dy2)
758+ si lon1 == 0 ou lon2 == 0 :
759+ continuer
760+ n1x = dy1 / lon1
761+ n1y = - dx1 / lon1
762+ n2x = dy2 / lon2
763+ n2y = - dx2 / lon2
764+ _ajouter_tuile_3_direct(pvx, pvy, pvx + n1x * at, pvy + n1y * at, pvx + n2x * at, pvy + n2y * at, larg, haut)
705765 retour 0
706766
707767
@@ -737,35 +797,23 @@ def _gen_carre_snub(larg, haut, a):
737797 soit ta0x = tri_arete_x3(x0, y0, x1, y1)
738798 soit ta0y = tri_arete_y3(x0, y0, x1, y1)
739799 _ajouter_tuile_3_direct(x0, y0, x1, y1, ta0x, ta0y, larg, haut)
740- soit m0x = (x1 + x2) / 2.0
741- soit m0y = (y1 + y2) / 2.0 + a * 0.55
742- _ajouter_tuile_3_direct(x1, y1, x2, y2, m0x, m0y, larg, haut)
743800 soit ta1x = tri_arete_x3(x1, y1, x2, y2)
744801 soit ta1y = tri_arete_y3(x1, y1, x2, y2)
745802 _ajouter_tuile_3_direct(x1, y1, x2, y2, ta1x, ta1y, larg, haut)
746- soit m1x = (x2 + x3) / 2.0
747- soit m1y = (y2 + y3) / 2.0 - a * 0.55
748- _ajouter_tuile_3_direct(x2, y2, x3, y3, m1x, m1y, larg, haut)
749803 soit ta2x = tri_arete_x3(x2, y2, x3, y3)
750804 soit ta2y = tri_arete_y3(x2, y2, x3, y3)
751805 _ajouter_tuile_3_direct(x2, y2, x3, y3, ta2x, ta2y, larg, haut)
752- soit m2x = (x3 + x0) / 2.0
753- soit m2y = (y3 + y0) / 2.0 + a * 0.55
754- _ajouter_tuile_3_direct(x3, y3, x0, y0, m2x, m2y, larg, haut)
755806 soit ta3x = tri_arete_x3(x3, y3, x0, y0)
756807 soit ta3y = tri_arete_y3(x3, y3, x0, y0)
757808 _ajouter_tuile_3_direct(x3, y3, x0, y0, ta3x, ta3y, larg, haut)
758- soit m3x = (x0 + x1) / 2.0
759- soit m3y = (y0 + y1) / 2.0 - a * 0.55
760- _ajouter_tuile_3_direct(x0, y0, x1, y1, m3x, m3y, larg, haut)
761809 x = x + pas
762810 y = y + pas
763811 retour 0
764812
765813
766814def _gen_rhombitrihex(larg, haut, a):
767- pas_x = 2.0 * (apotheme( 6 , a) + apotheme( 4 , a ))
768- pas_y = math.sqrt( 3.0 ) * (apotheme( 6 , a) + apotheme( 4 , a ))
815+ pas_x = a * (2.0 + math.sqrt( 3.0 ))
816+ pas_y = a * (1.5 + math.sqrt( 3.0 ))
769817 rang = 0
770818 y = - pas_y
771819 tantque y < = haut + pas_y:
@@ -820,25 +868,62 @@ def _gen_rhombitrihex(larg, haut, a):
820868 lon = math.sqrt(dx * dx + dy * dy)
821869 si lon == 0 :
822870 continuer
823- nx = - dy / lon
824- ny = dx / lon
825- apo4 = apotheme(4 , a)
826- ccx = (p1x + p2x) / 2.0 + nx * apo4
827- ccy = (p1y + p2y) / 2.0 + ny * apo4
828- tx = dx / lon
829- ty = dy / lon
830- demi = a / 2.0
831- soit q0x = ccx + (tx + nx) * demi
832- soit q0y = ccy + (ty + ny) * demi
833- soit q1x = ccx + (- tx + nx) * demi
834- soit q1y = ccy + (- ty + ny) * demi
835- soit q2x = ccx + (- tx - nx) * demi
836- soit q2y = ccy + (- ty - ny) * demi
837- soit q3x = ccx + (tx - nx) * demi
838- soit q3y = ccy + (ty - ny) * demi
839- _ajouter_tuile_4_direct(q0x, q0y, q1x, q1y, q2x, q2y, q3x, q3y, larg, haut)
840- apo3 = apotheme(3 , a)
841- _ajouter_tuile_3_direct(p1x, p1y, p2x, p2y, (p1x + p2x) / 2.0 + nx * apo3, (p1y + p2y) / 2.0 + ny * apo3, larg, haut)
871+ _ajouter_carre_depuis_arete(p1x, p1y, p2x, p2y, larg, haut)
872+ pour i dans range(6 ):
873+ vx = h0x
874+ vy = h0y
875+ ppx = h5x
876+ ppy = h5y
877+ pnx = h1x
878+ pny = h1y
879+ si i == 1 :
880+ vx = h1x
881+ vy = h1y
882+ ppx = h0x
883+ ppy = h0y
884+ pnx = h2x
885+ pny = h2y
886+ si i == 2 :
887+ vx = h2x
888+ vy = h2y
889+ ppx = h1x
890+ ppy = h1y
891+ pnx = h3x
892+ pny = h3y
893+ si i == 3 :
894+ vx = h3x
895+ vy = h3y
896+ ppx = h2x
897+ ppy = h2y
898+ pnx = h4x
899+ pny = h4y
900+ si i == 4 :
901+ vx = h4x
902+ vy = h4y
903+ ppx = h3x
904+ ppy = h3y
905+ pnx = h5x
906+ pny = h5y
907+ si i == 5 :
908+ vx = h5x
909+ vy = h5y
910+ ppx = h4x
911+ ppy = h4y
912+ pnx = h0x
913+ pny = h0y
914+ dx1 = vx - ppx
915+ dy1 = vy - ppy
916+ dx2 = pnx - vx
917+ dy2 = pny - vy
918+ lon1 = math.sqrt(dx1 * dx1 + dy1 * dy1)
919+ lon2 = math.sqrt(dx2 * dx2 + dy2 * dy2)
920+ si lon1 == 0 ou lon2 == 0 :
921+ continuer
922+ n1x = dy1 / lon1
923+ n1y = - dx1 / lon1
924+ n2x = dy2 / lon2
925+ n2y = - dx2 / lon2
926+ _ajouter_tuile_3_direct(vx, vy, vx + n1x * a, vy + n1y * a, vx + n2x * a, vy + n2y * a, larg, haut)
842927 x = x + pas_x
843928 rang = rang + 1
844929 y = y + pas_y
@@ -892,11 +977,8 @@ def _gen_carre_tronque(larg, haut, a):
892977
893978
894979def _gen_grand_rhombitrihex(larg, haut, a):
895- apo12 = apotheme(12 , a)
896- apo6 = apotheme(6 , a)
897- apo4 = apotheme(4 , a)
898- pas_x = 2.0 * (apo12 + apo6 + apo4)
899- pas_y = math.sqrt(3.0 ) * (apo12 + apo6 + apo4)
980+ pas_x = a * (5.0 + math.sqrt(3.0 ))
981+ pas_y = a * (4.1 + math.sqrt(3.0 ))
900982 rang = 0
901983 y = - pas_y
902984 tantque y < = haut + pas_y:
@@ -993,41 +1075,10 @@ def _gen_grand_rhombitrihex(larg, haut, a):
9931075 lon = math.sqrt(dx * dx + dy * dy)
9941076 si lon == 0 :
9951077 continuer
996- nx = - dy / lon
997- ny = dx / lon
998- mx = (p1x + p2x) / 2.0
999- my = (p1y + p2y) / 2.0
10001078 si i % 2 == 0 :
1001- soit hx = mx + nx * apo6
1002- soit hy = my + ny * apo6
1003- soit h0x = sommet_hex_x(hx, hy, a, 0 )
1004- soit h0y = sommet_hex_y(hx, hy, a, 0 )
1005- soit h1x = sommet_hex_x(hx, hy, a, 1 )
1006- soit h1y = sommet_hex_y(hx, hy, a, 1 )
1007- soit h2x = sommet_hex_x(hx, hy, a, 2 )
1008- soit h2y = sommet_hex_y(hx, hy, a, 2 )
1009- soit h3x = sommet_hex_x(hx, hy, a, 3 )
1010- soit h3y = sommet_hex_y(hx, hy, a, 3 )
1011- soit h4x = sommet_hex_x(hx, hy, a, 4 )
1012- soit h4y = sommet_hex_y(hx, hy, a, 4 )
1013- soit h5x = sommet_hex_x(hx, hy, a, 5 )
1014- soit h5y = sommet_hex_y(hx, hy, a, 5 )
1015- _ajouter_tuile_6_direct(h0x, h0y, h1x, h1y, h2x, h2y, h3x, h3y, h4x, h4y, h5x, h5y, larg, haut)
1079+ _ajouter_hex_depuis_arete(p1x, p1y, p2x, p2y, larg, haut)
10161080 sinon:
1017- ccx = mx + nx * apo4
1018- ccy = my + ny * apo4
1019- tx = dx / lon
1020- ty = dy / lon
1021- demi = a / 2.0
1022- soit q0x = ccx + (tx + nx) * demi
1023- soit q0y = ccy + (ty + ny) * demi
1024- soit q1x = ccx + (- tx + nx) * demi
1025- soit q1y = ccy + (- ty + ny) * demi
1026- soit q2x = ccx + (- tx - nx) * demi
1027- soit q2y = ccy + (- ty - ny) * demi
1028- soit q3x = ccx + (tx - nx) * demi
1029- soit q3y = ccy + (ty - ny) * demi
1030- _ajouter_tuile_4_direct(q0x, q0y, q1x, q1y, q2x, q2y, q3x, q3y, larg, haut)
1081+ _ajouter_carre_depuis_arete(p1x, p1y, p2x, p2y, larg, haut)
10311082 x = x + pas_x
10321083 rang = rang + 1
10331084 y = y + pas_y
0 commit comments