
! script name: conics.d/trochoid
! topic: construct spline curve through trochoid

!A
!A NAME:
!A
!A 	Trochoid
!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]
DEG

Stat=SetInputFormat("n4","")

ActivateUndo
Group_loop:!
Group=CreateGroup("TEMPGROUP")
Pt_count=1

R1=InputRadius("RADIUS OF ROLLING CIRCLE")
IF (ExitScript(Destination$)) THEN Leave

N1=GetValue("NUMBER OF REVOLUTIONS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

R2=InputRadius("RADIUS OF ROLLING POINT")
IF (ExitScript(Destination$)) THEN Leave

Center=XyzInput("CENTER POINT OF BASE CIRCLE ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Angle= N1*360
Ang_inc= 10
Nsteps= INT(ABS(Angle)/Ang_inc)+1
Ang_inc= Angle/Nsteps

Astart= 0.0
Xcen=XPointValue(Center)
Ycen=YPointValue(Center)
Zcen=ZPointValue(Center)

PlotOff
Stat= DeleteEntity(Center)
FOR I=0 TO Nsteps
	Ang= Astart+I*Ang_inc
	A1=Ang*PI/180.0
	X= Xcen+ R1*A1- R2*SIN(Ang)
	Y= Ycen+ R1- R2*COS(Ang)
	Z= Zcen

	Pt= PointXYZ(X,Y,Z)

	Stat=AddToGroup(Group,Pt)

	Pt_count=Pt_count+1
NEXT I

Spline_group=CSCurvePtGrp(Group,Pt,0,Pt,0)
Stat=DeleteGroup(Group)
Stat=DeleteEntity(Center)
Stat=DeleteEntity(Pt)
PlotOn
Stat=PlotEntity(Spline_group)

ActivateUndo
Stat= AdvanceUndoNumber("trochoid")
Stat= AddItemToUndo(WsUBCreateMode,Spline_group)
GOTO Group_loop


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

