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

!A
!A NAME:
!A
!A 	Trochoid   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a spline curve through a trochoid.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF ROLLING CIRCLE: Enter the radius of the rolling circle for the
!B				trochoid.
!B
!B
!B 	NUMBER OF REVOLUTIONS : Enter the total number of revolutions of
!B 		rolling circle.
!B
!B 	RADIAL DISTANCE TO POINT: Radial distance to point on rolling circle.
!B
!B
!C NOTE:
!C	
!C	A trochoid is generated by the locus of a point on the radius of 
!C	a circle while the circle is rolled along the positive x axis.
!C

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

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:!

Stat=SetInputFormat("n4=","")
R1=InputRadius("RADIUS OF ROLLING CIRCLE")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)

Stat=SetInputFormat("n4=","")
Angle=GetValue("TOTAL ANGLE OF REVOLUTION",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Stat=SetInputFormat("n4=","")
R2=InputRadius("RADIUS OF ROLLING POINT")
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("TROCHOID: 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("Rolling circle radius",R1)
ELSE
        V1= FreeParameter("Rolling circle radius",Radius_var$)
END IF
IF No_rolling_var THEN
        V2= FreeParameter("Radius of rolling point",R2)
ELSE
        V2= FreeParameter("Radius of rolling point",Rolling_var$)
END IF
V3=FreeParameter("Starting angle",Astart)
IF No_angle_var THEN
	V4= FreeParameter("Angle",Angle)
ELSE
	V4= FreeParameter("Angle",Angle_var$)
END IF
V5=FreeParameter("Angular increment",5)
E1=Trochoid(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("trochoid")
Stat= AddItemToUndo(WsUBCreateMode,E1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
ELSE
	DelLastVarRecord
END IF
GOTO Start_loop

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

