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

!A
!A NAME:
!A
!A 	EPICYCLOID
!A
!A DESCRIPTION:
!A
!A 	This script constructs a spline curve through a epicycloid.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF  CIRCLE: Enter the radius of the base circle for the
!B 		epicycloid.
!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	around a fixed circle.
!C

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

DIM Answer$[256]
DIM Destination$[256]
DEG

Stat=SetInputFormat("n4","")

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

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


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

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


Astart= 0
Angle= 360
Ang_inc= 3
Nsteps= INT(ABS(Angle)/Ang_inc)+1
Ang_inc= Angle/Nsteps

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

PlotOff
Stat= DeleteEntity(Center)
FOR I=0 TO Nsteps
	Ang= Astart+I*Ang_inc
	A1= (R1+R2)/R2*Ang
	X= Xcen+ (R1+R2)*COS(Ang)- R2*COS(A1)
	Y= Ycen+ (R1+R2)*SIN(Ang)- R2*SIN(A1)
	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("epicycloid")
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

