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

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

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

DIM Answer$[256]
DIM Destination$[256]
DIM Radius_var$[256]
DIM Dist_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$)

H=GetValue("DISTANCE TO CENTER OF ROLLONG CIRCLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_dist_var= LastVariableInput(Dist_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("HYPOTROCHOID: 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
IF No_dist_var THEN
        V6= FreeParameter("Distance to rolling circle center",H)
ELSE
        V6= FreeParameter("Distance to rolling circle center",Dist_var$)
END IF
V3=FreeParameter("Starting angle",Astart)
V4= FreeParameter("Angle",Angle)
V5=FreeParameter("Angular increment",Ang_inc)
E1=Hypotrochoid(Pc,V1,V2,V6,V3,V4,V5)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
IF ValidGeometry(E1) THEN
Stat= AdvanceUndoNumber("hypotrochoid")
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

