
! script name: nurbs.d/bezierthrupts
! topic: Sample - construct bezier curve through group of points

!A
!A NAME:
!A
!A 	Bezier (through points)
!A
!A DESCRIPTION:
!A
!A 	This script constructs a Bezier curve through a group of points.
!A 	A Bezier curve is a polynomial of degree n-1 through n points.
!A 	Control points are created and may be edited.
!A
!B INSTRUCTIONS:
!B
!B 	POINT #  ABS X,Y,Z: Enter the X,Y,Z coordinates of a point on the
!B 		bspline curve.  Remember, the order of the points is important.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!C NOTES:
!C
!C 	Enter the last point twice to end the point input mode.
!C
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: Bezier (through points) ")

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

ActivateUndo
Highlight_color= 3
Max_deg=7
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Group_loop:!
Group=CreateGroup("TEMPGROUP")
Pt_count=1

Point_loop:!

Ploop:Pt=XyzInput("POINT #"&VAL$(Pt_count)&" ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

IF Pt_count>1 THEN
	Dist=DistTwoPts(Pt,Plast)
	IF (Dist>0.0001) THEN
		Stat=AddToGroup(Group,Pt)
		Stat=SetLastPoint(Pt,WsXyzInput)
		Stat= SetSelectedFlag(Pt,WsTrue)
        	Stat= PlotEntity(Pt)
		Plast=Pt
		Pend=Pt
		Pt_count=Pt_count+1
		GOTO Point_loop
	END IF
ELSE
	Stat=AddToGroup(Group,Pt)
	Stat=SetLastPoint(Pt,WsXyzInput)
	Stat= SetSelectedFlag(Pt,WsTrue)
        Stat= PlotEntity(Pt)
	Plast=Pt
	Pstart=Pt
	Pt_count=Pt_count+1
	GOTO Point_loop
END IF

Spline_group=InterpolatePtGrp(Group,7,0,Max_deg+1,0)
Stat=DeleteGroup(Group)
Stat=DeleteEntity(Pt)

ActivateUndo
Stat= AdvanceUndoNumber("bezier curve")
Stat= AddGroupToUndo(WsUBCreateMode,Spline_group,1,WsFalse)
GOTO Group_loop


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

