CurvePointCount doesn't return the right number on closed curves

Hi everyone,
I wonder why the rhinoscript “CurvePointCount” method doesn’t return the right number of points on closed curves:
A closed curve with a kink at the start/end returns 1 point too much
A closed curve smooth all around returns 3 points too much

What is the reason for this and how can I obtain the correct point count?

thanks Tobias

Hi @tobias,

Can you post the curve and a sample script in question?


– Dale

Hi Dale,
Sure. See this example file
CurvePointCount.3dm (270.3 KB)

Btw CurveEditPoints (Ubound+1) returns the same numbers.

s = Rhino.GetObject
i = Rhino.CurvePointCount (s)
rhino.print i
a = Rhino.CurveEditPoints (s)
rhino.print Ubound(a)+1

There must be some underlying logic which I don’t know or understand.

greetins, Tobias

Hi @tobias,

If you use Rhino’s What command, you’ll see that Rhino.CurvePointCount is returning the correct value.

But the ExtractPt command does not extract every control point. If it did, you’d end up with duplicates in cases where you have closed and periodic curves.

My VBScript is a big rusty. But this is basically what the ExtractPt does.

Option Explicit

Call ExtractPt()

Sub ExtractPt()
	Const rhCurve = &h4
	Dim strCurve, arrPoints, i
	Dim nCount, nFirst, nLast, nDegree
	strCurve = Rhino.GetObject("Select curve for point extraction", rhCurve, True)
	If IsNull(strCurve) Then Exit Sub
	arrPoints = Rhino.CurvePoints(strCurve)
	If Not IsArray(arrPoints) Then Exit Sub

	nCount = UBound(arrPoints)
	nFirst = 0
	If Rhino.IsCurveClosed(strCurve) Then
		nlast = nCount - 1
		nLast = nCount
	End If
	If Rhino.IsCurvePeriodic(strCurve) Then
		nDegree = Rhino.CurveDegree(strCurve)
		nFirst = CInt(nDegree / 2)
		nLast = nCount - nDegree + nFirst
	End If
	For i = nFirst To nLast
		Call Rhino.AddPoint(arrPoints(i))
End Sub

Hope this helps.

– Dale

Thanks Dale!
I still don’t know really why there is a difference in the number of points you get when you turn on control points, or why some of the points are duplicated, but I can life with that lack of knowledge (for now) :wink:

greets, Tobias

Hi @tobias,

Create a rectangle that is 10 x 10. Then select it and run the List command.

ON_PolylineCurve:  domain = [0,40]
    point[ 0] = (0, 0, 0), 0
    point[ 1] = (10, 0, 0), 10
    point[ 2] = (10, 10, 0), 20
    point[ 3] = (0, 10, 0), 30
    point[ 4] = (0, 0, 0), 40

Notice how the rectangle has 5 points, but you only see 4 on the screen. This is because the first and lst points match, thus making a closed curve.

When you turn on the grip for the rectangle, you only see 4 points - the duplicate grip is not created as it would cause confusion when editing.

Hope this helps.

– Dale

Thanks Dale!
Yes, that makes indeed perfect sense.
Thanks for taking the time to clarify things. Well appreciated!

greetings, Tobias