Circles of given radius through two points: Difference between revisions

Content added Content deleted
(Updated D entry)
Line 1,344: Line 1,344:
#<struct Circle x=0.1234, y=0.9876, r=0.0>
#<struct Circle x=0.1234, y=0.9876, r=0.0>
</pre>
</pre>

=={{header|Run BASIC}}==
<lang rnbasic>
html "<TABLE border=1>"
html "<tr bgcolor=wheat align=center><td>No.</td><td>x1</td><td>y1</td><td>x2</td><td>y2</td><td>r</td><td>cir x1</td><td>cir y1</td><td>cir x2</td><td>cir y2</td></tr>"
for i = 1 to 5
read x1, y1, x2, y2,r
html "<tr align=right><td>";i;"</td><td>";x1;"</td><td>";y1;"</td><td>";x2;"</td><td>";y2;"</td><td>";r;"</td>"
gosub [twoCircles]
next
html "</table>"
end

'p1 p2 r
data 0.1234, 0.9876, 0.8765, 0.2345, 2.0
data 0.0000, 2.0000, 0.0000, 0.0000, 1.0
data 0.1234, 0.9876, 0.1234, 0.9876, 2.0
data 0.1234, 0.9876, 0.8765, 0.2345, 0.5
data 0.1234, 0.9876, 0.1234, 0.9876, 0.0

[twoCircles]

if x1=x2 and y1=y2 then '2.If the points are coincident
if r=0 then ' unless r==0.0
html "<td colspan=4 align=left>It will be a single point (";x1;",";y1;") of radius 0</td></tr>"
RETURN
else
html "<td colspan=4 align=left>There are any number of circles via single point (";x1;",";y1;") of radius ";r;"</td></tr>"
RETURN
end if
end if
r2 = sqr((x1-x2)^2+(y1-y2)^2)/2 'half distance between points
if r<r2 then
html "<td colspan=4 align=left>Points are too far apart (";2*r2;") - there are no circles of radius ";r
RETURN
end if

'else, calculate two centers
cx=(x1+x2)/2 'middle point
cy=(y1+y2)/2
'should move from middle point along perpendicular by dd2
dd2=sqr(r^2-r2^2) 'perpendicular distance
dx1=x2-cx 'vector to middle point
dy1=y2-cy
dx = 0-dy1/r2*dd2 'perpendicular:
dy = dx1/r2*dd2 'rotate and scale
html "<td>";cx+dy;"</td><td>";cy+dx;"</td>" 'two points, with (+)
html "<td>";cx-dy;"</td><td>";cy-dx;"</td></TR>" 'and (-)
RETURN</lang>
{{Out}}<TABLE BORDER="1">
<TR ALIGN="CENTER" BGCOLOR="wheat"><TD>No.</TD><TD>x1</TD><TD>y1</TD><TD>x2
</TD><TD>y2</TD><TD>r</TD><TD>cir x1</TD><TD>cir y1</TD><TD>cir x2</TD><TD>cir y2</TD></TR>
<TR ALIGN="RIGHT">
<TD>1</TD><TD>0.1234</TD><TD>0.9876</TD><TD>0.8765</TD><TD>0.2345</TD><TD>2.0</TD><TD>1.8631118</TD><TD>1.9742118</TD><TD>-0.863211802</TD><TD>-0.752111802</TD></TR>
<TR ALIGN="RIGHT"><TD>2</TD><TD>0.0d</TD><TD>2.0</TD><TD>0.0d</TD><TD>0.0d</TD><TD>1.0</TD><TD>0.0d</TD><TD>1.0</TD><TD>0.0d</TD><TD>1.0</TD></TR>
<TR ALIGN="RIGHT"><TD>3</TD><TD>0.1234</TD><TD>0.9876</TD><TD>0.1234</TD><TD>0.9876</TD><TD>2.0</TD>
<TD ALIGN="LEFT" COLSPAN="4">There are any number of circles via single point (0.1234,0.9876) of radius 2.0</TD></TR>
<TR ALIGN="RIGHT"><TD>4</TD><TD>0.1234</TD><TD>0.9876</TD><TD>0.8765</TD><TD>0.2345</TD><TD>0.5</TD>
<TD ALIGN="LEFT" COLSPAN="4">Points are too far apart (1.06504423) - there are no circles of radius 0.5</TD></TR>
<TR ALIGN="RIGHT"><TD>5</TD><TD>0.1234</TD><TD>0.9876</TD><TD>0.1234</TD><TD>0.9876</TD><TD>0.0d</TD>
<TD ALIGN="LEFT" COLSPAN="4">It will be a single point (0.1234,0.9876) of radius 0</TD></TR>
</TABLE>


=={{header|Rust}}==
=={{header|Rust}}==
Line 1,421: Line 1,483:
Points : ((0.1234, 0.9876), (0.1234, 0.9876)) Radius : 0.0000
Points : ((0.1234, 0.9876), (0.1234, 0.9876)) Radius : 0.0000
No circles can be drawn through (0.1234, 0.9876)</pre>
No circles can be drawn through (0.1234, 0.9876)</pre>

=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<lang seed7>$ include "seed7_05.s7i";