Curve that touches three points: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: don't need the off-site image any longer) |
(Added FreeBasic) |
||
Line 226: | Line 226: | ||
[100, 200.000000] |
[100, 200.000000] |
||
[200, 10.000000]</pre> |
[200, 10.000000]</pre> |
||
=={{header|FreeBASIC}}== |
|||
{{trans|Ada}} |
|||
<syntaxhighlight lang="vb">' Point P1 |
|||
Dim As Double X1 = 10.0 |
|||
Dim As Double Y1 = 10.0 |
|||
' Point P2 |
|||
Dim As Double X2 = 100.0 |
|||
Dim As Double Y2 = 200.0 |
|||
' Point P3 |
|||
Dim As Double X3 = 200.0 |
|||
Dim As Double Y3 = 10.0 |
|||
' Point P4 - midpoint between P1 and P2 |
|||
Dim As Double X4 = (X1 + X2) / 2.0 |
|||
Dim As Double Y4 = (Y1 + Y2) / 2.0 |
|||
Dim As Double S4 = (Y2 - Y1) / (X2 - X1) ' Slope P1-P2 |
|||
Dim As Double A4 = -1.0 / S4 ' Slope P4-Center |
|||
' Y4 = A4 * X4 + B4 <=> B4 = Y4 - A4 * X4 |
|||
Dim As Double B4 = Y4 - A4 * X4 |
|||
' Point P5 - midpoint between P2 and P3 |
|||
Dim As Double X5 = (X2 + X3) / 2.0 |
|||
Dim As Double Y5 = (Y2 + Y3) / 2.0 |
|||
Dim As Double S5 = (Y3 - Y2) / (X3 - X2) ' Slope P2-P3 |
|||
Dim As Double A5 = -1.0 / S5 ' Slope P5-Center |
|||
' Y5 = A5 * X5 + B5 <=> B5 = Y5 - A5 * X5 |
|||
Dim As Double B5 = Y5 - A5 * X5 |
|||
' Find center |
|||
' Y = A4 * X + B4 ' Line 1 |
|||
' Y = A5 * X + B5 ' Line 2 |
|||
' Solve for X: |
|||
' A4 * X + B4 = A5 * X + B5 |
|||
' A4 * X - A5 * X = B5 - B4 |
|||
' X * (A4 - A5) = B5 - B4 |
|||
' X = (B5 - B4) / (A4 - A5) |
|||
Dim As Double Xc = (B5 - B4) / (A4 - A5) |
|||
Dim As Double Yc = A4 * Xc + B4 |
|||
' Radius |
|||
Dim As Double R = Sqr((X1 - Xc) ^ 2 + (Y1 - Yc) ^ 2) |
|||
Print Using "Center : (###.#, ###.#)"; Xc; Yc |
|||
Print Using "Radius : ###.#"; R |
|||
Sleep</syntaxhighlight> |
|||
=={{header|Go}}== |
=={{header|Go}}== |