问题描述
为了找到解决方案,我已经阅读过类似的主题,但没有成功。
我想要做的是使工具与在CorelDraw中找到的相同,名称为钢笔工具。我通过连接贝塞尔三次曲线来完成,但仍然缺少一个特征,即拖动曲线(而不是控制点)以编辑其形状。
我可以成功确定拖动应该开始的曲线上的t参数,但不知道如何重新计算该曲线的控制点。
在这里,我想强调一些相关的事情CorelDraw'的PenTool行为可以作为constaints使用。我注意到,严格垂直或水平拖动曲线时,该贝塞尔曲线的控制点会相应地表现出来,即它们分别在垂直方向或水平方向移动。
那么,如何在拖动曲线的同时重新计算控制点的位置?
// Magic Bezier Drag Equations跟着!
//weight描述了拖动的影响应该如何分配到
//中; 0 =仅限前手柄,1 =仅限后手柄。
双重重量,t = _t;如果(t ; (t else weight = 1;
Geom :: Point delta = new_pos - position();
Geom :: Point offset0 =((1-weight)/(3 * t *(1-t)*(1-t)))* delta;
Geom :: Point offset1 =(weight /(3 * t * t *(1-t)))* delta; $(> front() - > position()+ offset0);
first-> front() - > move
second-> back() - > move(second-> back() - > position()+ offset1);
在你的例子中,first-> front()和second-> back()意味着两个控制点
I have read similar topics in order to find solution, but with no success.What I'm trying to do is make the tool same as can be found in CorelDraw, named "Pen Tool". I did it by connecting Bezier cubic curves, but still missing one feature, which is dragging curve (not control point) in order to edit its shape.
I can successfully determine the "t" parameter on the curve where dragging should begin, but don't know how to recalculate control points of that curve.
Here I want to higlight some things related to CorelDraw''s PenTool behaviour that may be used as constaints. I've noticed that when dragging curve strictly vertically, or horizontally, control points of that Bezier curve behave accordingly, i.e. they move on their verticals, or horizontals, respectively.
So, how can I recalculate positions of control points while curve dragging?
Ive just look into Inkspace sources and found such code, may be it help you:
// Magic Bezier Drag Equations follow!
// "weight" describes how the influence of the drag should be distributed
// among the handles; 0 = front handle only, 1 = back handle only.
double weight, t = _t;
if (t <= 1.0 / 6.0) weight = 0;
else if (t <= 0.5) weight = (pow((6 * t - 1) / 2.0, 3)) / 2;
else if (t <= 5.0 / 6.0) weight = (1 - pow((6 * (1-t) - 1) / 2.0, 3)) / 2 + 0.5;
else weight = 1;
Geom::Point delta = new_pos - position();
Geom::Point offset0 = ((1-weight)/(3*t*(1-t)*(1-t))) * delta;
Geom::Point offset1 = (weight/(3*t*t*(1-t))) * delta;
first->front()->move(first->front()->position() + offset0);
second->back()->move(second->back()->position() + offset1);
In you case "first->front()" and "second->back()" would mean two control points
这篇关于贝塞尔曲线通过三点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!