Curve that touches three points: Difference between revisions
Content added Content deleted
(added RPL) |
(Added PHP) |
||
Line 1,533: | Line 1,533: | ||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</syntaxhighlight>--> |
<!--</syntaxhighlight>--> |
||
=={{header|PHP}}== |
|||
Finds a circle that passes through those three points. Adapted from AutoHotkey. |
|||
<syntaxhighlight lang="PHP"> |
|||
function circle_3_points($x1, $y1, $x2, $y2, $x3, $y3) { |
|||
$x4 = ($x1 + $x2) / 2.0; |
|||
$y4 = ($y1 + $y2) / 2.0; |
|||
$s4 = ($y2 - $y1) / ($x2 - $x1); |
|||
$a4 = -1.0 / $s4; |
|||
$b4 = $y4 - $a4 * $x4; |
|||
$x5 = ($x2 + $x3) / 2.0; |
|||
$y5 = ($y2 + $y3) / 2.0; |
|||
$s5 = ($y3 - $y2) / ($x3 - $x2); |
|||
$a5 = -1.0 / $s5; |
|||
$b5 = $y5 - $a5 * $x5; |
|||
$xc = ($b5 - $b4) / ($a4 - $a5); |
|||
$yc = $a4 * $xc + $b4; |
|||
$r = √(²($x1 - $xc) + ²($y1 - $yc)); |
|||
return [$xc, $yc, $r]; |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |