
! script name: circles.d/twoptstangent
! topic: construct circle tangent to element and passing through two points

!A
!A NAME:
!A
!A 	Two Points: Tangent
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle tangent to an element and passing
!A 	through two defined points.  The tangent element to be picked must
!A 	be a circle, line, or point.
!A
!A~ image location - images/twopointstangent.jpg
!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 constructed
!B 		will pass.
!B
!B 	PICK THIRD TANGENT ELEMENT: Pick the third element that
!B 		will be tangent to the circle constructed.
!B
!# see also - points.d/xyzinput.hlp

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

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

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
IF Graphical_mode THEN LOAD "circles.d/dyntwoptstangent"
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: !
E3=PickEntity("PICK THIRD TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
T3=LastPickPara

C1=ThreeTangents(P1,T1,P2,T2,E3,T3,0)

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

GOTO Ploop

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