This forum has been archived. All content is frozen. Please use KDE Discuss instead.

looking for help with Bezier

Tags: None
(comma "," separated)
lucyla
Registered Member
Posts
2
Karma
0

looking for help with Bezier

Mon Apr 19, 2021 3:19 pm
I'm trying to find some specifications for how a click-and-drag on Bezier curves can reshape them - specifically, in Krita in a vector drawing layer, I can click on a segment and drag my mouse / stylus and the Bezier handles move to place the control points in the right place so the curve passes through the place I selected.

Looking at the basic maths of bezier has led me to a place where I think what I'm missing is a set of assumptions that make the maths solvable. And I'm hoping that someone here can enlighten me.

In summary -- I have P0 and P3 fixed. I know the starting values of P1 and P2. I click on a point B in the segment - and that is t% into the segment - and I drag B...

I am struggling to calculate new values for P1 and P2 based on the required movement of B -- any relevant help (pointer to the specification or source code file; a simple "you're missing this"; "it only works if you assume this") would be most gratefully received.
ghevan
Registered Member
Posts
178
Karma
1
OS

Re: looking for help with Bezier

Mon Apr 19, 2021 3:37 pm
Hi!

did you check the utilities at KisBezierUtils.h it seems
Code: Select all
std::pair<QPointF, QPointF> offsetSegment(qreal t, const QPointF &offset);

does what you need

In case it doesn't be sure to check the other methods available.

If there is none I come with the next reasoning: A cubic bezier can be expressed as a polinomial in the form
Code: Select all
a(1-t)^3 + bt(1-t)^2 + ct^2(1-t) + dt^3 = p
, in your case you already know t, a, d, and p. and should solve for b and c (where a = P0 and d = P3). the problem arises from getting the value just right as the adjustment of P1 and P2 depends on the size of 't'. in "offsetSegment" the use an arbitrary parameter to adjust the influence on each solution for P1 and P2 depending on how big if "t"

Hope it helps!


lucyla
Registered Member
Posts
2
Karma
0

Re: looking for help with Bezier

Tue Apr 20, 2021 7:04 am
Thanks - I found the code you referenced -- but it says "It is not used anywhere is Krita yet (was developed as part of testing
for free patch deform action)." -- even so I'll take a good long look at what's there.

I'm aware of the bezier polynomial - but, as you point out, that ends up with two unknowns (P1, P2) for which the resolution seems to be to make them somehow interdependent based on t?


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]