Kindly excuse me in advance if i am asking wrong question at wrong place.
I am very fresh user of Rhino and came across one problem.
I am trying to create NurbsCurve all seems works well, however I have small misunderstanding when reading DXF entity`s (Spline) i am getting following data:
134 control points.
137 knots.
degree 3. ( update : Typo degree = 2)
When NurbsCurve object is created the props “NurbsCurveKnotList Knots” is the list of size 134 element, and i am just stupid cannot get my head around how i can fit 137 knots to array size of 134 element
Was playing around whole day and reading the docus but no success.
I will highly appreciate for any help, and once again sorry if i am asking stupid question.
I am trying to learn API of Rhino to create some pluggin for our customer.
Basically I am reading DXF file with aspose library and I am getting those values by traversing through the entities, maybe library just giving wrong value as you point out it should follow the formula.
I also stumbled across good math books explaining nurbs and it says the same.
Hi Tom,
Oh yeah I did for sure. I tried to go over theory before jumping to the code.
Seems aspose lib which I am using to parse the dxf returns me wrong information.
I was just confused if interpreting formula wrong or doing something not correctly
Hi @dale thanks a lot for your time and response.
I will definitely read through your suggestion - 100% need to boost my knowledge as feeling like blind groundhog…
I removed 1 and last knot and i am getting very good result apart that some beiziers sadly null and missing
Oh i did knew i can do this with Rhino… i have to give a try.
P.S
I also found that i am currently using Rhino3dm nuget and not RhinoCommon but sadly it is still not targeting .net 8 which makes it incompatible with the rest of our internal code.
To give a bit of context we do laser machines and one of our important customer use Rhino and he love it much so we are building some special solution for him.
Basically our laser consumes polylines, beziers and arc, and to get best quality i am trying to get beziers out of splines.
So far result is pretty good however i have some beziers gets back “null” after calling →
when i plot the result the Rhino does amazing job but yeah i guess i am doing something wrong.
The red line is original piece of spline
The green one is result of the code bellow. Almost everything is there apart of small bezier missing (just one example).
private PathShape Convert(
List<PointF> controlPoints,
List<double> knots,
List<double> weights,
int degree,
bool isRational,
AffineTransform transform
)
{
var nurbsCurve = new NurbsCurve(3, isRational, degree + 1, controlPoints.Count);
for (int i = 0; i < nurbsCurve .Points.Count; i++)
{
var point = new Point3d((double)controlPoints[i].X, (double)controlPoints[i].Y, 0);
// weight are zero at this DXF file so can be ignored for this sample.
nurbsCurve .Points[i] = new ControlPoint(point, 0);
}
// Remove first and last knot (0,1) https://developer.rhino3d.com/guides/opennurbs/superfluous-knots/
knots.RemoveAt(0);
knots.RemoveAt(knots.Count() - 1);
for (int i = 0; i < nurbsCurve .Knots.Count; i++)
{
nurbsCurve2.Knots[i] = knots[i];
}
var result = new List<SimpleSegment>();
for (int i = 0; i < nurbsCurve2.SpanCount; i++)
{
BezierCurve bezierCurves = nurbsCurve2.ConvertSpanToBezier(i);
if (bezierCurves is null)
{
... // find why this happens ?
}
var countOfVertex = bezierCurves.ControlVertexCount;
if (countOfVertex == 3)
{
// quadratic bezier curve
}
else (countOfVertex == 4)
{
// cubic bezier
}
}
....
Added to your code possibility to Explode nurb to smaller bezier and result is great at least with one customer file
Laser will be finally happy process beziers instead of poly-lines.