Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic knot calculation #3

Closed
ctrlcctrlv opened this issue May 30, 2021 · 4 comments
Closed

Automatic knot calculation #3

ctrlcctrlv opened this issue May 30, 2021 · 4 comments

Comments

@ctrlcctrlv
Copy link

Hello,

I'm wondering why there's not a way for me to just use control points to get a BSpline? Why can't there be some default knot vector?

@Twinklebear
Copy link
Owner

Twinklebear commented May 30, 2021

Hi,

A similar question was asked on #2 , which might answer your question as well. In short: this library just does B-spline interpolation, which takes the control points and knots and interpolates between them. Computing a B-spline curve that passes through some points is B-spline approximation, which takes some points you want the curve to pass through (or pass closely enough by) and computes the control points and knots that define that curve. B-Spline approximation is much more complicated than interpolation, requiring a linear system solve and other approximation techniques. The course slides here on "Global Curve Approximation" discuss it some: http://www.cad.zju.edu.cn/home/zhx/GM/009/00-bsia.pdf

As mentioned on #2 scipy provides a method to compute the B-Spline for a set of points: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.splprep.html . You could use that to try out the process of approximating the curve and handing those control points and knots to this library to interpolate it to see how it all fits together. But to keep this library small, it just does interpolation.

@ctrlcctrlv
Copy link
Author

ctrlcctrlv commented May 30, 2021

Oh, thanks for the explanation. Scipy won't work for me. I'm working on a Rust application, it's a font editor. It's also realtime…I need to calculate the cubic Bezier for the B-Spline as user drags a point. Python, especially CPython, won't do for that at all, especially because it means a costly double conversion of the path data in and out of Python land. You wouldn't happen to know a Rust method for doing this, would you? Or do I need to re-implement some C library?

Are you open for being commissioned? I'd happily pay you to write this. It'd be a single function: given a Vec of points , come up with the cubic Bezier. Either in kurbo CubicBez or glifparser.rlib Outline format. ⅓ upfront, ⅔ afterwards. Crypto payment available. Hit me up :-)

@Twinklebear
Copy link
Owner

Gotcha, the project looks cool! I don't know of a B-spline approximation library, but these might be more useful for a font application where you might also want derivatives or other info:

I'm not sure if either of those provides approximation though.

Splines are cool, but unfortunately I don't think I'd have the time to add an approximation feature to this library. Your use case though (2D cubic B-Spline) is a lot easier than a general case that I was initially thinking you meant. The stroke-rs library looks pretty actively developed and targets a wider feature set, that author might be interested in adding some approximation support if they don't have it already.

@ctrlcctrlv
Copy link
Author

stroke-rs may do it, I'll let you know if it does. Right now I'm adding a bunch of pens and this one was specifically requested, so kind of got bumped on my priorities :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants