
! script name: vsolids.d/sphere2pts
! var_topic: 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

ActivateUndo
Sphere_loop:!
Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("CENTER POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)


Pick_point2:Stat=SetInputFormat("n4=","")
E1=PickEntity("SECOND POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point2
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E1,Point$)
P2= ParameterReturnPt(E1,T2,Pick_return2)
Stat=SetLastPoint(P2)
Stat= DeleteEntity(P2)



Stat= GenerateVarName(WsSphereSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SPHERE: Two points")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        P2= ParameterReturnPt(Point$,T2,WsGeometryEnd)
CASE WsGeometryMid
        P2= ParameterReturnPt(Point$,T2,WsGeometryMid)
CASE WsGeomCenter
        P2= ParameterReturnPt(Point$,T2,WsGeomCenter)
END SELECT
Trans1=AngleTransform(Pc,0,0,0)
S1=Sphere(Trans1,DistTwoPts(Pc,P2))
Stat= NameEntity(S1,Name$)
Stat= DeleteEntityList(Pc,P2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("sphere")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
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
