Circles of given radius through two points: Difference between revisions

no edit summary
No edit summary
Line 3,004:
0.1234 0.9876 0.1234 0.9876 0 radius of zero gives no circles.
</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>DataSection
DataStart:
Data.d 0.1234, 0.9876, 0.8765, 0.2345, 2.0
Data.d 0.0000, 2.0000, 0.0000, 0.0000, 1.0
Data.d 0.1234, 0.9876, 0.1234, 0.9876, 2.0
Data.d 0.1234, 0.9876, 0.9765, 0.2345, 0.5
Data.d 0.1234, 0.9876, 0.1234, 0.9876, 0.0
DataEnd:
EndDataSection
Macro MaxRec : (?DataEnd-?DataStart)/SizeOf(P2r)-1 : EndMacro
 
Structure Pxy : x.d : y.d : EndStructure
Structure P2r : p1.Pxy : p2.Pxy : r.d : EndStructure
Structure PData : Prec.P2r[5] : EndStructure
 
Procedure.s cCenter(Rec.i)
If Rec<0 Or Rec>MaxRec : ProcedureReturn "Data set number incorrect." : EndIf
*myP.PData=?DataStart
r.d=*myP\Prec[Rec]\r
If r<=0.0 : ProcedureReturn "Illegal radius." : EndIf
r2.d=2.0*r
x1.d=*myP\Prec[Rec]\p1\x : x2.d=*myP\Prec[Rec]\p2\x
y1.d=*myP\Prec[Rec]\p1\y : y2.d=*myP\Prec[Rec]\p2\y
d.d=Sqr(Pow(x2-x1,2)+Pow(y2-y1,2))
If d=0.0 : ProcedureReturn "Identical points, infinite number of circles." : EndIf
If d>r2 : ProcedureReturn "No circles possible." : EndIf
z.d=Sqr(Pow(r,2)-Pow(d/2.0,2))
x3.d =(x1+x2)/2.0 : y3.d =(y1+y2)/2.0
cx1.d=x3+z*(y1-y2)/d : cy1.d=y3+z*(x2-x1)/d
cx2.d=x3-z*(y1-y2)/d : cy2.d=y3-z*(x2-x1)/d
If d=r2 : ProcedureReturn "Single circle at ("+StrD(cx1)+","+StrD(cy1)+")" : EndIf
ProcedureReturn "("+StrD(cx1)+","+StrD(cy1)+") and ("+StrD(cx2)+","+StrD(cy2)+")"
EndProcedure
 
If OpenConsole("")
For i=0 To MaxRec : PrintN(cCenter(i)) : Next : Input()
EndIf</lang>
{{out}}
<pre>(1.8631118017,1.9742118017) and (-0.8632118017,-0.7521118017)
Single circle at (0,1)
Identical points, infinite number of circles.
No circles possible.
Illegal radius.</pre>
 
=={{header|Python}}==
164

edits