
! script name: circles.d/threepoints
! topic: construct circle through three points

!A
!A NAME:
!A
!A 	Three Points
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of unknown radius through three points.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT FIRST POINT ABS X,Y: Enter the X,Y coordinates of the
!B 		first point, through which the circle constructed will pass.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	INPUT SECOND POINT ABS X,Y: Enter the X,Y coordinates of
!B 		the second point, through which the circle
!B 		constructed will pass.
!B
!B 	INPUT THIRD POINT ABS X,Y: Enter the X,Y coordinates of the
!B 		third point, through which the circle constructed will pass.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: three points ")

DIM Destination$[256]
DIM Answer$[256]

DEG

ActivateUndo
stat= SetInputFormat("n4","")
Ploop:!
ON ERROR GOTO Error_check
P1=XyzInput("INPUT FIRST POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
T1=0

Point2: !
P2=XyzInput("INPUT SECOND POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
T2=0

Ptdist=DistTwoPts(P1,P2)
IF Ptdist>.000098 THEN Point3
Stat=DeleteEntity(P2)
GOTO Point2

Point3: !
P3=XyzInput("INPUT THIRD POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
T3=0
Ptdist=DistTwoPts(P2,P3)
Ptdist2=DistTwoPts(P1,P3)
IF Ptdist>.000098 AND Ptdist2>.000098 THEN Circle
Stat=DeleteEntity(P3)
GOTO Point3

Circle: !
C1=ThreeTangents(P1,T1,P2,T2,P3,T3,0)

Error_check: OFF ERROR
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(P3)
ActivateUndo
Stat= AdvanceUndoNumber("circle")
Stat= AddItemToUndo(WsUBCreateMode,C1)

GOTO Ploop

Leave:!
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(P3)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
