
! script name: conics.d/test1
! 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:!
R1=InputRadius("OUTER RADIUS")
IF (ExitScript(Destination$)) THEN Leave

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

Ps=XyzInput("START POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Next_point:!
Pe=XyzInput("END POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Width_cut= 0.125

L1= DistTwoPts(Ps,Pe)
IF L1< 0.001 THEN Leave
N1= L1/Width_cut
N1= INT(N1)+1

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

Astart= 0.0
Xs=XPointValue(Ps)
Ys=YPointValue(Ps)
Zs=ZPointValue(Ps)
Xe=XPointValue(Pe)
Ye=YPointValue(Pe)
Ze=ZPointValue(Pe)


PlotOff
R= R1-R2
Group=CreateGroup("TEMPGROUP")
FOR I=0 TO Nsteps
	T= I/Nsteps
	Ang= Astart+T*Angle
	Xcen= Xs+ T*(Xe-Xs)
	Ycen= Ys+ T*(Ye-Ys)
	Zcen= Zs+ T*(Ze-Zs)
	X= Xcen+ R*COS(Ang) 
	Y= Ycen+ R*SIN(Ang)
	Z= Zcen

	Pt= PointXYZ(X,Y,Z)

	Stat=AddToGroup(Group,Pt)
NEXT I

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

ActivateUndo
Stat= AdvanceUndoNumber("trochoid")
Stat= AddItemToUndo(WsUBCreateMode,Spline_group)
Ps= PointXYZ(Xe,Ye,Ze)
GOTO Next_point


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

