
! script name: vpksheets.d/vpksphere2pts
! var_solids: construct sphere defined by two unique points

!A
!A NAME:
!A
!A 	Sphere: Two Points	VARIATIONAL
!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 the center
!B 		point.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	SECOND POINT ABS X,Y,Z: Enter the X,Y,Z coordinates for the second
!B 		point.  The distance between the CENTER POINT and the SECOND
!B 		POINT will determine the radius of the sphere.
!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/xyzinput.hlp

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

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

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

Stat= GLPlotOn
Sphere_loop:!
ActivateUndo
Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("CENTER POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Pick_point2:Stat=SetInputFormat("n4=","")
P2=XyzInput("SECOND POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(P2) THEN Pick_point2
E1= LastPickEnt
Pick_para2= LastPickPara
Pick_return2= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(P2)
        Stat= EntityNameCheck(E1,Point$)
        P2_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point$)
        P2_created= WsFalse
END IF
Stat=SetLastPoint(P2)
Stat= DeleteEntity(P2)



WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Sphere two points")
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        P2= ParameterReturnPt(Point$,Pick_para2,WsGeometryEnd)
CASE WsGeometryMid
        P2= ParameterReturnPt(Point$,Pick_para2,WsGeometryMid)
CASE WsGeomCenter
        P2= ParameterReturnPt(Point$,Pick_para2,WsGeomCenter)
END SELECT
Trans1=AngleTransform(Pc,0,0,0)
S1=Sphere(Trans1,DistTwoPts(Pc,P2))
RecordFunctionOff
IF ValidGeometry(S1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        G1=WPKMakeBsurf(S1)
        Stat= WPKNameBodyGroup(G1,Name$)
        Stat= WPKSetBodyParent(G1,1)
        Stat= DeleteEntityList(G1,S1)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOn
Stat= DeleteEntityList(Pc,P2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
        IF Pc_created THEN Stat= DeleteEntity(Center$)
        IF P2_created THEN Stat= DeleteEntity(Point$)
        DelLastVarRecord
ELSE
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("spherical sheet")
        IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
        IF P2_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Sphere_loop

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