
! script name: vcircles.d/centerpoint
! var_topic: construct circle defined by center and tangent point

!A
!A NAME:
!A
!A 	Center: Point   VARIATIIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of unknown radius about a point
!A 	tangent to a known point.
!A
!A~ image location - images/centerandpoint.jpg
!B INSTRUCTIONS:
!B
!B 	INPUT CENTER ABS X,Y: Enter the X,Y coordinates of the center point
!B 		of the circle.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	INPUT ABS X,Y: Enter the X,Y coordinates of the known point which
!B 		will be used to construct the circle tangent to this point.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: center: point ")

DIM Destination$[256]
DIM Answer$[256]
DIM Center$[256]
DIM Point$[256]


DEG
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave


ActivateUndo
stat= SetInputFormat("n4","")
Circle_loop:!
E1=PickEntity("CENTER POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
IF NOT ValidDependency(E1) THEN Pick_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T1,Pick_return1)

Stat=SetLastPoint(Pc)
E2=PickEntity("TANGENT POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E2) THEN Pick_loop
IF NOT ValidDependency(E2) THEN Pick_loop
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point$)
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pe)


Stat= GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE: Center tangent point")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point$,T2,WsGeomCenter)
END SELECT
C1=CenterTangent(Pc,Pe,Pe)
Stat= NameEntity(C1,Name$)
Stat= DeleteEntityList(Pc,Ps)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Center$)
Stat= PlotEntity(Point$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("center tangent")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF


GOTO Circle_loop

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