How to resolve the algorithm Circles of given radius through two points step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Circles of given radius through two points step by step in the BASIC programming language
Table of Contents
Problem Statement
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Circles of given radius through two points step by step in the BASIC programming language
Source code in the basic programming language
function twoCircles(x1, y1, x2, y2, radio)
if x1 = x2 and y1 = y2 then #Si los puntos coinciden
if radio = 0 then #a no ser que radio=0
print "Los puntos son los mismos "
return ""
else
print "Hay cualquier número de círculos a través de un solo punto ("; x1; ", "; y1; ") de radio "; int(radio)
return ""
end if
end if
r2 = sqr((x1-x2)^2+(y1-y2)^2) / 2 #distancia media entre puntos
if radio < r2 then
print "Los puntos están demasiado separados ("; 2*r2; ") - no hay círculos de radio "; int(radio)
return ""
end if
#si no, calcular dos centros
cx = (x1+x2) / 2 #punto medio
cy = (y1+y2) / 2
#debe moverse desde el punto medio a lo largo de la perpendicular en dd2
dd2 = sqr(radio^2 - r2^2) #distancia perpendicular
dx1 = x2-cx #vector al punto medio
dy1 = y2-cy
dx = 0-dy1 / r2*dd2 #perpendicular:
dy = dx1 / r2*dd2 #rotar y escalar
print " -> Circulo 1 ("; cx+dy; ", "; cy+dx; ")" #dos puntos, con (+)
print " -> Circulo 2 ("; cx-dy; ", "; cy-dx; ")" #y (-)
return ""
end function
# p1 p2 radio
x1 = 0.1234 : y1 = 0.9876 : x2 = 0.8765 : y2 = 0.2345 : radio = 2.0
print "Puntos "; "("; x1; ","; y1; "), ("; x2; ","; y2; ")"; ", Radio "; int(radio)
print twoCircles (x1, y1, x2, y2, radio)
x1 = 0.0000 : y1 = 2.0000 : x2 = 0.0000 : y2 = 0.0000 : radio = 1.0
print "Puntos "; "("; x1; ","; y1; "), ("; x2; ","; y2; ")"; ", Radio "; int(radio)
print twoCircles (x1, y1, x2, y2, radio)
x1 = 0.1234 : y1 = 0.9876 : x2 = 0.12345 : y2 = 0.9876 : radio = 2.0
print "Puntos "; "("; x1; ","; y1; "), ("; x2; ","; y2; ")"; ", Radio "; int(radio)
print twoCircles (x1, y1, x2, y2, radio)
x1 = 0.1234 : y1 = 0.9876 : x2 = 0.8765 : y2 = 0.2345 : radio = 0.5
print "Puntos "; "("; x1; ","; y1; "), ("; x2; ","; y2; ")"; ", Radio "; int(radio)
print twoCircles (x1, y1, x2, y2, radio)
x1 = 0.1234 : y1 = 0.9876 : x2 = 1234 : y2 = 0.9876 : radio = 0.0
print "Puntos "; "("; x1; ","; y1; "), ("; x2; ","; y2; ")"; ", Radio "; int(radio)
print twoCircles (x1, y1, x2, y2, radio)
end
You may also check:How to resolve the algorithm MD5 step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the Stata programming language
You may also check:How to resolve the algorithm Hickerson series of almost integers step by step in the Tcl programming language
You may also check:How to resolve the algorithm Prime numbers whose neighboring pairs are tetraprimes step by step in the Phix programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the PicoLisp programming language