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

!A
!A NAME:
!A
!A 	Bezier Curve
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bezier curve using a group of points
!A	as control points.
!A 	A bezier curve is a polynomial, the degree of the polynomial is
!A 	equal to the number of points minus one, and is tangent at both
!A 	ends of the curve, and is influenced by the weight of the other
!A 	points.
!A
!A~ image location - images/beziercurve.jpg
!B INSTRUCTIONS:
!B
!B 	CONTROL POINT #  ABS X,Y: Enter the X,Y coordinates of the point.
!B 		Remember, the order of the points is important.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B NOTES:
!B
!B 	Enter the last point twice to end the point input mode.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: bezier curve ")

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

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

Point_loop:!

Ploop:Pt=XyzInput("CONTROL 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
		Pt_count=Pt_count+1
		Stat= DeleteEntity(Sp)
		Sp=BSplinePtGrp(Group,0,3)
		GOTO Point_loop
	END IF
ELSE
	Stat=AddToGroup(Group,Pt)
	Stat=SetLastPoint(Pt,WsXyzInput)
	Stat= SetSelectedFlag(Pt,WsTrue)
        Stat= PlotEntity(Pt)
	Plast=Pt
	Pt_count=Pt_count+1
	GOTO Point_loop
END IF

Stat= DeleteEntity(Sp)
Sp=BSplinePtGrp(Group,0,3)
Stat=DeleteGroup(Group)
Stat=DeleteEntity(Pt)

ActivateUndo
Stat= AdvanceUndoNumber("bezier curve")
Stat= AddItemToUndo(WsUBCreateMode,Sp)
LOAD "nurbs.d/beziercurve"
GOTO Group_loop


Leave:!
IF ValidGeometry(Sp) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("bezier curve")
	Stat= AddItemToUndo(WsUBCreateMode,Sp)
END IF
Stat=DeleteEntity(Pt)
Stat=DeleteGroup(Group)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

