Divide a rectangle into a number of unequal triangles: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Perl}}: fix my wrongdoing)
m (syntax highlighting fixup automation)
Line 15:
=={{header|Julia}}==
The `cutrectangle` method creates a new triangle by consuming a previously created triangle by cutting it at a location determined by the ratio of two sequential primes, making for guaranteed noncongruence of all triangles thus made. The Luxor code is for the demo. See also <link>https://lynxview.com/temp/luxor-drawing.png</link>
<langsyntaxhighlight lang="julia">using Colors
using Luxor
using Primes
Line 54:
finish()
preview()
</langsyntaxhighlight>{{out}}
<pre>
t = Triangle(Point(200.0, 0.0), Point(150.0, 150.0), Point(105.0, 105.0))
Line 69:
=={{header|Perl}}==
All triangle vertices lie on the lengths and the corners and their locations are defined by ratios among two sequences with unique numbers. Since the height is the same but with different base for all triangles, none will share the area.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 109:
 
my @V = UnequalDivider(1000,500,7);
say sprintf( '(%.3f %.3f) 'x3, @{$V[$_]}, @{$V[++$_]}, @{$V[++$_]} ) =~ s/\.000//gr for 0 .. @V-3;</langsyntaxhighlight>
{{out}}
<pre>(0 500) (0 0) (352.941 500)
Line 125:
and penned a wee little interactive visualisation demo of it, that can be run [http://phix.x10.mx/p2js/SpliRT.htm here].
Should you find a way to make it draw similar triangles, shout out and let me know n and canvas size!
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo/rosetta/SpliRT.exw </span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 232:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Python}}==
Line 239:
It is assumed that the rectangle has its bottom left coordinate at (0,0) and is not rotated in the coordinate space, meaning that the location of the top-right corner of the rectangle is then enough to define it.
 
<langsyntaxhighlight lang="python">
import random
from typing import List, Union, Tuple
Line 440:
print("\nrect_into_top_tri #2")
pp(rect_into_top_tri((2, 1), 4, 10))
</syntaxhighlight>
</lang>
 
{{out}}
Line 471:
=={{header|Raku}}==
The first triangle bisects the rectangle via the diagonal. The rest of them all got one vertex at the origin and a side defined by ratios of numbers from a descending positive integer sequence.
<syntaxhighlight lang="raku" perl6line># 20220123 Raku programming solution
 
# Proof :
Line 500:
}
 
.say for UnequalDivider(1000,500,5);</langsyntaxhighlight>
{{out}}
<pre>
Line 519:
 
This process should ensure that all the triangles are different, albeit the first one is usually much larger than the others. However, to be absolutely sure, we check that the areas of all the triangles are different.
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "./seq" for Lst
 
Line 587:
}
System.print()
}</langsyntaxhighlight>
 
{{out}}
10,327

edits