
! script name: vconics.d/parabola_directrix
! var_topic: create parabola defined by focus and directrix

!A
!A NAME:
!A
!A 	Parabola (focus,directrix)   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a parabola with known focus and known directrix.
!A 	A parabola is the locus of points such that any point on the parabola
!A 	is equidistant from a fixed point, called the focus, and a fixed line,
!A 	called the directrix.
!A
!B INSTRUCTIONS:
!B
!B 	FOCUS POINT ABS X,Y: Enter the X,Y
!B 		coordinates of the focus point of the parabola.
!B
!B	PICK DIRECTRIX LINE: Select the line that is the directrix.
!B
!C NOTES:
!C
!C 	The standard equation of a parabola with focus at (0,P) and directrix
!C 	at Y=-P is:
!C
!C 		X^2=4PY
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: parabola (focus,directrix) ")

DIM Answer$[256]
DIM Destination$[256]
DIM Vertex$[256]
DIM Focus$[256]
DIM Length_var$[256]
DIM Name$[256]
DIM Name1$[256]
DEG


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

Length= 5.0

ActivateUndo
Parabola_loop:!
E1=PickEntity("FOCUS POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Parabola_loop
Stat= EntityNameCheck(E1,Focus$)
Pick_para1= LastPickPara
Pick_return1= CurrPickReturn

Stat=SetInputFormat("n4","")
L1=PickSpecificEnt("PICK DIRECTRIX LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(L1) THEN Parabola_loop
Stat= EntityNameCheck(L1,Name1$)

Stat=SetEqualsValue(Length)
Stat=SetInputFormat("n4=","")
Length=GetValue("LENGTH ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_len_var= LastVariableInput(Length_var$)
IF Length< 0.0001 THEN Leave


Stat= GenerateVarName(WsBSplineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PARABOLA: focus,directrix")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Focus$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Focus$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Focus$,Pick_para1,WsGeomCenter)
END SELECT
IF No_len_var THEN
	V1= FreeParameter("Length",Length)
ELSE
	V1= FreeParameter("Length",Length_var$)
END IF
P2= Intersect(Name1$,Pe,Pe)
L1=LineTwoPoints(Pe,P2)
Vertex=ParameterPt(L1,0.5)
E1=Parabola(Vertex,Pe,V1)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Pe,P2,L1,Vertex)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

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