
! script name: dyn_solids.d/dynsphere2pts
! 3dtopic: construct sphere defined by two unique points

!A
!A NAME:
!A
!A 	Dynamic Sphere: Two Points
!A
!A DESCRIPTION:
!A
!A 	This script allows a sphere to be defined by two unique points.
!A
!B INSTRUCTIONS:
!B
!B 	CENTER POINT ABS X,Y,Z: Enter the X,Y,Z coordinates for
!B 		the center point.  NOTE: See XYZ INPUT OPTIONS.
!B
!C NOTES:
!C
!C 	The U contours of a sphere are the circles from the starting length
!C 	to the ending length.  The V contours of a sphere are the circles 
!C 	formed from the starting angle to the ending angle.
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: sphere defined by 2 points ")

DIM Answer$[256]
DIM Destination$[256]
REAL Params(0:10)

DEG

Stat= GLPlotOn
Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Stat=SetAngleEquals(0)
Astart=InputAngle("STARTING ANGLE ( 0 90 180 270 ) ")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4b=","")
Stat=SetEqualsValue(180)
Angle=GetValue("ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave

Pick_center:!
Stat=DynLabel("Astart:"&VAL$(Astart)&":Angle:"&VAL$(Angle))
Stat=SetInputFormat("n4b","")
Pc=XyzInput("CENTER POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_center

Stat=SetLastPoint(Pc)

PlotOff
Length1= 1.0
Pt= PtIncrXyz(Pc,Length1,0.0,0.0)
Trans1=AngleTransform(Pc,0,0,0)
C1=Sphere(Trans1,Radius,-Radius,Radius,Astart,Angle)
Stat= MakeInvisible(C1)
Stat= MakeInvisible(Pc)
Stat= MakeInvisible(Pt)
PlotOn

Vnum= LastPickView
Params(0)= Astart
Params(1)= Angle
Num_params=2
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Pc,Pt,WsDynTwoPtSphere,"PICK POINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(Pc)
        Stat=DeleteEntity(Pt,WsTrue)
        Stat=DeleteEntity(C1,WsTrue)
        IF Destination$= "BACKUP" THEN Pick_center
        GOTO Leave
END IF
Astart=Params(0)
Angle=Params(1)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pt)


WPKClearErrorFlag
S1=WPKMakeBsurf(C1)
Stat= DeleteEntity(C1,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("sphere sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Pick_center

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pt)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "BACKUP" THEN Start
        IF Destination$= "SCRIPTSTART" THEN Start
	LOAD Destination$
END IF
END
