
! script name: circles.d/rad2points
! topic: construct arc defined by end points and radius

!A
!A NAME:
!A
!A 	Rad: Two Points
!A
!A DESCRIPTION:
!A
!A 	This script constructs an arc of known radius with the two end points
!A 	defined.
!A
!A~ image location - images/rad2points.jpg
!B INSTRUCTIONS:
!B
!B 	CIRCLE RADIUS: Enter radius of arc to be constructed.
!B
!B 	FIRST POINT ABS X,Y: Enter the X,Y coordinates of the first point,
!B 		which will be one of the end points of the arc constructed.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B	
!B 	NEXT POINT ABS X,Y: Enter the X,Y coordinates of the next point,
!B 		which will be the other end point of the arc constructed.
!B
!B 	PICK LEFT/RIGHT OF LINE JOINING POINTS: Pick side of line that the
!B 		arc will be constructed on.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: rad: two points ")

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


DEG

ActivateUndo
stat= SetInputFormat("n4","")
Radius=InputRadius("CIRCLE RADIUS")
IF (ExitScript(Destination$)) THEN Leave

Circle_loop:!
ON ERROR GOTO Error_check
P1=XyzInput("FIRST POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

Point2: !
P2=XyzInput("NEXT POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

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


Line1: !
L1=LineTwoPoints(P1,P2,WsTRIMMED)

Pt=InputFreePoint("PICK LEFT/RIGHT OF LINE JOINING POINTS")
IF (ExitScript(Destination$)) THEN Leave

S1=PtLeftRight(L1,Pt)

IF S1=1 THEN
	Which_one=1
ELSE
	Which_one=2
END IF

!C If the following line is unremmed the construction will be an arc.
!C C1=Fillet(Radius,P1,1,P2,1,Which_one,WsTRIMMED)
   C1=Fillet(Radius,P1,1,P2,1,Which_one,WsTRIMMED)

!C If the following line is unremmed the construction will be a circle.
!C C1=Fillet(Radius,P1,1,P2,1,Which_one,WsUNTRIMMED)

Error_check: OFF ERROR
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(L1)
Stat=DeleteEntity(Pt)

ActivateUndo
Stat= AdvanceUndoNumber("circle")
Stat= AddItemToUndo(WsUBCreateMode,C1)
GOTO Circle_loop

Leave:!
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(L1)
Stat=DeleteEntity(Pt)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
