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?
Can you post the curve and a sample script in question?
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)
a = Rhino.CurveEditPoints (s)
There must be some underlying logic which I don’t know or understand.
If you use Rhino’s
What command, you’ll see that
Rhino.CurvePointCount is returning the correct value.
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
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
If Rhino.IsCurvePeriodic(strCurve) Then
nDegree = Rhino.CurveDegree(strCurve)
nFirst = CInt(nDegree / 2)
nLast = nCount - nDegree + nFirst
For i = nFirst To nLast
Hope this helps.
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)
Create a rectangle that is 10 x 10. Then select it and run the
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.
Yes, that makes indeed perfect sense.
Thanks for taking the time to clarify things. Well appreciated!