Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.7k stars 230 forks source link

Find optmal D1 - Bezier.cubicFromPoints #195

Closed sysmaya closed 11 months ago

sysmaya commented 1 year ago

I am developing an svg editor. And as part of the project, I require a function that finds the MINIMUM number of nodes to create an SVG path. The idea is not to create a reduction, it is to recreate the shape (100% identical, if possible) but using the minimum number of nodes.

b1

I have created a function that iterates through the array of bezier points and finds those nodes. The question is to find the optimal value of d1. When I omit the value, the Bezier.cubicFromPoints function creates a value, which is almost perfect. Doing manual tests I found that the optimal value is: Distance( P1, P2 ) /6

In the attached image you can see that the nodes found do not allow degenerate curves to form. So the handles of the node should not be in remote positions, or deforming the curve too much.

I check the Bezier.js script and I see something like ABC, but I don't quite understand the concept.

Pomax commented 11 months ago

I'm not sure I understand what you're asking for, because it sounds like you're trying to implement curve fitting for arbitrary shapes, in which case: start at reading up on potrace (read the PDF that is linked in the "further reading" section) and then branch out from there, because shape abstraction has lots of people implementing it in lots of different ways.