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

!A
!A NAME:
!A
!A 	Helix
!A
!A DESCRIPTION:
!A
!A 	This script constructs a spline curve through a helix.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF HELIX: Enter the radius of the helix to be constructed.
!B
!B 	CENTER POINT ABS X,Y: Enter the X,Y coordinates of the center point
!B 		of the helix.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	STARTING ANGLE: Enter the starting angle of the helix.
!B
!B 	ANGULAR EXTENT: Enter the total number of degrees for the helix
!B 		construction.
!B
!B 	Z START: Enter the Z coordinate of the start point of the helix.
!B
!B 	Z END: Enter the Z coordinate of the end point of the helix.
!B
!# see also - points.d/xyzinput.hlp

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

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

ActivateUndo
Stat=SetInputFormat("n4","")
Group_loop:!
Group=CreateGroup("TEMPGROUP")
Pt_count=1

Radius=InputRadius("RADIUS OF HELIX")
IF (ExitScript(Destination$)) THEN Leave

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

Astart=InputAngle("STARTING ANGLE")
IF (ExitScript(Destination$)) THEN Leave

Angle=InputAngle("ANGULAR EXTENT")
IF (ExitScript(Destination$)) THEN Leave

Zstart=GetValue("Z START",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Zend=GetValue("Z END",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Ang_inc=20
Nsteps= INT(ABS(Angle)/Ang_inc)+1
Ang_inc=Angle/Nsteps
Delz=(Zend-Zstart)/Nsteps

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

PlotOff
FOR I=0 TO Nsteps
	Ang=Astart+I*Ang_inc
	X=Xcen+Radius*COS(Ang)
	Y=Ycen+Radius*SIN(Ang)
	Z=Zstart+I*Delz

	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("helix")
Stat= AddItemToUndo(WsUBCreateMode,Spline_group)
GOTO Group_loop


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

