
! script name: vconics.d/hypocycloid
! var_topic: construct spline curve through hypocycloid

!A
!A NAME:
!A
!A 	HYPOCYCLOID   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a spline curve through a hypocycloid.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF  CIRCLE: Enter the radius of the base circle for the
!B 		hypocycloid.
!B
!B 	RADIUS OF ROLLING CIRCLE: Radius of the rolling circle.
!B
!C NOTE:
!C	
!C	An epicycloid is generated by a point on a circle rolling
!C	inside a fixed circle.
!C

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

DIM Answer$[256]
DIM Destination$[256]
DIM Radius_var$[256]
DIM Angle_var$[256]
DIM Rolling_var$[256]
DIM Name$[256]
DEG

Stat=SetInputFormat("n4","")
Astart=0
Angle=360
Ang_inc=3

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

ActivateUndo
Start_loop:!

R1=InputRadius("RADIUS OF BASE CIRCLE")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)

R2=InputRadius("RADIUS OF ROLLING CIRCLE")
IF (ExitScript(Destination$)) THEN Leave
No_rolling_var= LastVariableInput(Rolling_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)

Stat= GenerateVarName(WsCSplineCurveEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("HYPOCYCLOID: spline curve")
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_radius_var THEN
        V1= FreeParameter("Base radius",R1)
ELSE
        V1= FreeParameter("Base radius",Radius_var$)
END IF
IF No_rolling_var THEN
        V2= FreeParameter("Rolling radius",R2)
ELSE
        V2= FreeParameter("Rolling radius",Rolling_var$)
END IF
V3=FreeParameter("Starting angle",Astart)
V4= FreeParameter("Angle",Angle)
V5=FreeParameter("Angular increment",Ang_inc)
E1=Hypocycloid(Pc,V1,V2,V3,V4,V5)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

Leave:!
PlotOn
Stat= DynLabel("")
Stat=DeleteEntity(Center)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

