Curve that touches three points: Difference between revisions

Added AutoHotkey
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(Added AutoHotkey)
Line 5:
::#  Do not use functions of a library, implement the curve() function yourself
::#  coordinates:(x,y) starting point (10,10) medium point (100,200) final point (200,10)
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>QuadraticCurve(p1,p2,p3){ ; Y = aX^2 + bX + c
x1:=p1.1, y1:=p1.2, x2:=p2.1, y2:=p2.2, x3:=p3.1, y3:=p3.2
m:=x1-x2, n:=x3-x2, m:= ((m*n)<0?-1:1) * m
a:=(n*(y1-y2)+m*(y3-y2)) / (n*(x1**2 - x2**2) + m*(x3**2 - x2**2))
b:=((y3-y2) - (x3**2 - x2**2)*a) / (x3-x2)
c:=y1 - a*x1**2 - b*x1
return [a,b,c]
}</lang>
Examples:<lang AutoHotkey>P1 := [10,10], P2 := [100,200], P3 := [200,10]
v := QuadraticCurve(p1,p2,p3)
a := v.1, b:= v.2, c:= v.3
for i, X in [10,100,200]{
Y := a*X**2 + b*X + c ; Y = aX^2 + bX + c
res .= "[" x ", " y "]`n"
}
MsgBox % "Y = " a " X^2 " (b>0?"+":"") b " X " (c>0?"+":"") c " `n" res</lang>
; for plotting, use code from [https://rosettacode.org/wiki/Plot_coordinate_pairs#AutoHotkey RosettaCode: Plot Coordinate Pairs]
Outputs:<pre>Y = -0.021111 X^2 +4.433333 X -32.222222
[10, 10.000000]
[100, 200.000000]
[200, 10.000000]</pre>
 
=={{header|Go}}==
299

edits