
! script name: vconics.d/ellipse
! var_topic: create an ellipse

!A
!A NAME:
!A
!A 	Ellipse		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates an ellipse.  An ellipse is the locus of points
!A 	such that the sum of the distances from any point on the ellipse to
!A 	two fixed points, the foci, is a constant.
!A
!A~ image location - images/ellipse.jpg
!B INSTRUCTIONS:
!B
!B 	SEMI MAJOR AXIS: Enter the distance from
!B 		the center of the ellipse to a vertex.
!B
!B 	SEMI MINOR AXIS: Enter the distance from
!B 		the center of the ellipse to a vertex
!B 		perpendicular to the major axis.
!B
!B 	ELLIPSE CENTER ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the center of the ellipse.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ORIENTATION ANGLE: Enter the angle the ellipse
!B 		is to be oriented.
!B
!C NOTES:
!C
!C 	The standard equation of an ellipse is:
!C
!C 		X^2/A^2+Y^2/B^2=1
!C
!C 	The location of the foci may be calculated using:
!C
!C 		C^2=A^2-B^2    when A>B
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: ellipse ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Center$[256]
DIM Destination$[256]
DIM A_var$[256]
DIM B_var$[256]
DIM Angle_var$[256]
DEG

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

DEG

ActivateUndo
Start:!

Ellipse_loop:Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(A)
A=GetValue("SEMI MAJOR AXIS",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_a_var= LastVariableInput(A_var$)

Stat=SetEqualsValue(B)
B=GetValue("SEMI MINOR AXIS",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_b_var= LastVariableInput(B_var$)

Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("CENTER POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
Pick_para= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,Pick_para,Pick_return)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Angle=InputAngle("ORIENTATION ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Start_angle$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angle_ques
        Stat= EntityNameCheck(L1,Angle_var$)
        No_angle_var=0
END IF


Stat= GenerateVarName(WsEllipseEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("ELLIPSE: center")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_a_var THEN
        V1= FreeParameter("Major axis",A)
ELSE
        V1= FreeParameter("Major axis",A_var$)
END IF
IF No_b_var THEN
        V2= FreeParameter("Minor axis",B)
ELSE
        V2= FreeParameter("Minor axis",B_var$)
END IF
IF No_angle_var THEN
        V3= FreeParameter("Angle",Angle)
ELSE
        V3= FreeParameter("Angle",Angle_var$)
END IF
V4= FreeParameter("Start Angle",0)
V5= FreeParameter("End Angle",360)
E1=Ellipse(V1,V2,Pc,V4,V5,V3)
Stat= NameEntity(E1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
IF ValidGeometry(E1) THEN
Stat= AdvanceUndoNumber("ellipse")
Stat= AddItemToUndo(WsUBCreateMode,E1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
ELSE
	DelLastVarRecord
END IF

GOTO Start


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