Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

A question about B-Spline to Interpolated-Spline

emily_parker633emily_parker633 Member Posts: 4

I’d like to ask if there is a way to convert a B-Spline (defined by control points, knots, etc.) into an Interpolated-Spline (defined solely by a series of points, similar to the spline in Onshape UI).

The evCurveDefinition function returns the parameters of the B-spline (control points, knots, etc.), but the parameters I originally provided are a series of points (interpolated spline). Is it possible to retrieve the original points in FeatureScript?

The JSON data of features obtained through the API seems to have "interpolationPoints," but their coordinates appear to be in a 2D local coordinate system, rather than the actual coordinates.

Definition of bspline: https://github.com/onshape-public/onshape-clients/blob/4f613cc4025a90e11493e2b79560afe9762e1686/python/docs/BTCurveGeometrySpline118AllOf.md

Definition of interpolate spline: https://github.com/onshape-public/onshape-clients/blob/4f613cc4025a90e11493e2b79560afe9762e1686/python/docs/BTCurveGeometryInterpolatedSpline116.md

Best Answer

  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 228
    Answer ✓

    What is the use case you are intending here?

    You could approximate a given bspline at degree 3 (which is what interpolated curves are) then extract the position of the knots. This should get you pretty close to the locations of the "edit points" (as some systems call them) of an interpolated curve

    Quick example in FeatureScript to approximate at deg=3 then get the knots:

     const e = evApproximateBSplineCurve(context, {
                    "edge" : definition.edge,
                    "forceCubic" : true,
                    "forceNonRational" : true
                });
       
    
    
     for (var i = 0; i < size(e.knots); i += 1)
        {
    
            const knotPos = evEdgeTangentLine(context, {
                        "edge" : definition.edge,
                        "parameter" : e.knots[i]
                    });
    
            debug(context, knotPos.origin, DebugColor.MAGENTA);
    
        }
    

Answers

  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 228
    Answer ✓

    What is the use case you are intending here?

    You could approximate a given bspline at degree 3 (which is what interpolated curves are) then extract the position of the knots. This should get you pretty close to the locations of the "edit points" (as some systems call them) of an interpolated curve

    Quick example in FeatureScript to approximate at deg=3 then get the knots:

     const e = evApproximateBSplineCurve(context, {
                    "edge" : definition.edge,
                    "forceCubic" : true,
                    "forceNonRational" : true
                });
       
    
    
     for (var i = 0; i < size(e.knots); i += 1)
        {
    
            const knotPos = evEdgeTangentLine(context, {
                        "edge" : definition.edge,
                        "parameter" : e.knots[i]
                    });
    
            debug(context, knotPos.origin, DebugColor.MAGENTA);
    
        }
    

  • emily_parker633emily_parker633 Member Posts: 4

    Thank you, Greg, for your helpful answer.

    The use case I have in mind is creating a custom feature that may allows further operations based on the (interpolated)points.

Sign In or Register to comment.