How to resolve the algorithm Circles of given radius through two points step by step in the ERRE 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 ERRE 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 ERRE programming language
Source code in the erre programming language
PROGRAM CIRCLES
!
! for rosettacode.org
!
PROCEDURE CIRCLE_CENTER(X1,Y1,X2,Y2,R->MSG$)
LOCAL D,W,X3,Y3
D=SQR((X2-X1)^2+(Y2-Y1)^2)
IF D=0 THEN
MSG$="NO CIRCLES CAN BE DRAWN, POINTS ARE IDENTICAL"
EXIT PROCEDURE
END IF
X3=(X1+X2)/2 Y3=(Y1+Y2)/2
W=R^2-(D/2)^2
IF W<0 THEN
MSG$="NO SOLUTION"
EXIT PROCEDURE
END IF
CX1=X3+SQR(W)*(Y1-Y2)/D CY1=Y3+SQR(W)*(X2-X1)/D
CX2=X3-SQR(W)*(Y1-Y2)/D CY2=Y3-SQR(W)*(X2-X1)/D
IF D=R*2 THEN
MSG$="POINTS ARE OPPOSITE ENDS OF A DIAMETER CENTER = "+STR$(CX1)+","+STR$(CY1)
EXIT PROCEDURE
END IF
IF D>R*2 THEN
MSG$="POINTS ARE TOO FAR"
EXIT PROCEDURE
END IF
IF R<=0 THEN
MSG$="RADIUS IS NOT VALID"
EXIT PROCEDURE
END IF
MSG$=STR$(CX1)+","+STR$(CY1)+" & "+STR$(CX2)+","+STR$(CY2)
END PROCEDURE
BEGIN
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)
FOR I%=1 TO 5 DO
READ(PX,PY,QX,QY,RADIUS)
CIRCLE_CENTER(PX,PY,QX,QY,RADIUS->MSG$)
PRINT(MSG$)
END FOR
END PROGRAM
You may also check:How to resolve the algorithm Numbers with equal rises and falls step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Filter step by step in the Oz programming language
You may also check:How to resolve the algorithm Dot product step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Forth programming language
You may also check:How to resolve the algorithm Generate lower case ASCII alphabet step by step in the 8080 Assembly programming language