How to resolve the algorithm Circles of given radius through two points step by step in the Yabasic 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 Yabasic 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 Yabasic programming language

Source code in the yabasic programming language

sub 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\n"
			return true
		else
			print "Hay cualquier numero de circulos a traves de un solo punto (", x1, ",", y1, ") de radio ", radio : print
			return true
		end if
	end if
	r2 = sqr((x1-x2)^2+(y1-y2)^2) / 2  //distancia media entre puntos
	if radio < r2 then
		print "Los puntos estan demasiado separados (", 2*r2, ") - no hay circulos de radio ", radio : print
		return true
	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, ")\n"   //y (-)
end sub

for i = 1 to 5
	read x1, y1, x2, y2, radio
	print "Puntos ", "(", x1, ",", y1, "), (", x2, ",", y2, ")", ", Radio ", radio
	twoCircles (x1, y1, x2, y2, radio)
next
end

//p1                p2           radio
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

  

You may also check:How to resolve the algorithm Sleep step by step in the Applesoft BASIC programming language
You may also check:How to resolve the algorithm Undefined values step by step in the C programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the 11l programming language
You may also check:How to resolve the algorithm Make directory path step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the Julia programming language