Curve that touches three points: Difference between revisions

added RPL
(added RPL)
 
(2 intermediate revisions by 2 users not shown)
Line 1,632:
}</syntaxhighlight>
See [https://github.com/thundergnat/rc/blob/master/img/Curve-3-points-perl6.png Curve-3-points-perl6.png] (offsite .png image)
 
=={{header|RPL}}==
HP-49+ RPL has a built-in function named <code>LAGRANGE</code> that returns the curve equation from the 3 points, but let's consider it as belonging to a library.
{{works with|HP|48G}}
[[File:Parabol.png|thumb|right|alt=HP-48G emulator screenshot|HP-48G emulator screenshot]]
« → a b c
« { 0 0 0 }
c a - C→R SWAP / c b - RE /
b a - C→R SWAP / c b - RE / -
1 SWAP PUT
b a - C→R SWAP / OVER 1 GET b a + RE * -
2 SWAP PUT
a IM OVER 1 GET a RE SQ * - OVER 2 GET a RE * -
3 SWAP PUT
{ 'X^2' 'X' 1 } * ∑LIST
» » '<span style="color:blue">PAREQ</span>' STO
« # 131d # 64d PDIM 0 210 DUP2 XRNG YRNG
FUNCTION
(10,10) (100,200) (200,10)
3 DUPN <span style="color:blue">PAREQ</span> STEQ
ERASE DRAW
1 3 '''START''' PIXOFF '''NEXT''' <span style="color:grey">''@ switch off the 3 points on the curve''</span>
{ } PVIEW
{ PPAR EQ } PURGE
» '<span style="color:blue">TASK</span>' STO
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color, Point
import "dome" for Window
 
Line 1,682 ⟶ 1,708:
}
}</syntaxhighlight>
 
=={{header|XPL0}}==
[[File:XPL0_Curve.gif|200px|thumb|right]]
<syntaxhighlight lang "XPL0">def X0=10., Y0=10., X1=100., Y1=200., X2=200., Y2=10.;
 
func real Lagrange(X);
real X;
return (X-X1) * (X-X2) / (X0-X1) / (X0-X2) * Y0 +
(X-X0) * (X-X2) / (X1-X0) / (X1-X2) * Y1 +
(X-X0) * (X-X1) / (X2-X0) / (X2-X1) * Y2;
 
def Offset = 205;
real X;
[SetVid($13); \VGA 320x200x8 graphics
X:= X0;
Move(fix(X), Offset-fix(Y0));
repeat X:= X + 1.;
Line(fix(X), Offset-fix(Lagrange(X)), 3\cyan\);
until X >= X2;
Point(fix(X0), Offset-fix(Y0), 14\yellow\);
Point(fix(X1), Offset-fix(Y1), 14);
Point(fix(X2), Offset-fix(Y2), 14);
]</syntaxhighlight>
 
=={{header|zkl}}==
1,150

edits