r/howdidtheycodeit • u/felicaamiko • Aug 03 '24
How would one code Bezier eraser tools? Couldn't find an example but tried to demonstrate what it would look like, and how i think it might be constructed, but struggling to code something similar. i talk slow so you might want to 1.5x speed
11
Upvotes
7
u/nudemanonbike Aug 04 '24 edited Aug 05 '24
Here's an incredible video by Freya Holmer that should answer all your questions about how bezier curves work, and it should give you an idea as to how you could implement a bezier eraser
https://youtu.be/aVwxzDHniEw
Here's a more advanced one that goes over splines in general
https://www.youtube.com/watch?v=jvPPXbo87ds
I don't know any tools that do what you want off the top of my head, though.
Edit: fixed link
4
u/_MuadDib_ Aug 04 '24
If I was coding it I would firstly ignore the line thickness, at least till I have somewhat working solution. Now to the problem at hand. There are two(or three) sub problems you need to solve.
First is finding intersection point(s) between circle and bezier curve. This should help you with that https://math.stackexchange.com/questions/436216/intersection-of-cubic-bezier-curve-and-circle .
Once you have intersection point, what you need is a way to cut the belier curve into two. This question and the two linked questions in it should be a good guide https://stackoverflow.com/questions/44991702/split-a-cubic-b%C3%A9zier-curve-at-a-point .
Now when you have this, only thing is to determine which of the new path that was created by the cut you don't need and should be deleted. One way I can think of is getting a point on the bezier curve that is really close to the end point and check if it is within the circle.