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

Source code in the autohotkey programming language

CircleCenter(x1, y1, x2, y2, r){
	d := sqrt((x2-x1)**2 + (y2-y1)**2)
	x3 := (x1+x2)/2	, y3 := (y1+y2)/2
	cx1 := x3 + sqrt(r**2-(d/2)**2)*(y1-y2)/d , 	cy1:= y3 + sqrt(r**2-(d/2)**2)*(x2-x1)/d
	cx2 := x3 - sqrt(r**2-(d/2)**2)*(y1-y2)/d , 	cy2:= y3 - sqrt(r**2-(d/2)**2)*(x2-x1)/d
	if (d = 0)
		return "No circles can be drawn, points are identical"
	if (d = r*2)
		return "points are opposite ends of a diameter center = " cx1 "," cy1
	if (d = r*2)
		return "points are too far"
	if (r <= 0)
		return "radius is not valid"
	if !(cx1 && cy1 && cx2 && cy2)
		return "no solution"
	return cx1 "," cy1 " & " cx2 "," cy2
}


data = 
(
0.1234 0.9876 0.8765 0.2345 2.0
0.0000 2.0000 0.0000 0.0000 1.0
0.1234 0.9876 0.1234 0.9876 2.0
0.1234 0.9876 0.8765 0.2345 0.5
0.1234 0.9876 0.1234 0.9876 0.0
)

loop, parse, data, `n
{
	obj := StrSplit(A_LoopField, " ")
	MsgBox, % CircleCenter(obj[1], obj[2], obj[3], obj[4], obj[5])
}


  

You may also check:How to resolve the algorithm Comments step by step in the VBA programming language
You may also check:How to resolve the algorithm Repeat step by step in the Prolog programming language
You may also check:How to resolve the algorithm Chaos game step by step in the BASIC programming language
You may also check:How to resolve the algorithm Levenshtein distance step by step in the Arc programming language
You may also check:How to resolve the algorithm A+B step by step in the Little Man Computer programming language