gpt4 book ai didi

svg - inkscape 如何计算 "smooth edges"的控制点坐标?

转载 作者:行者123 更新时间:2023-12-01 14:31:07 25 4
gpt4 key购买 nike

我想知道如果路径上的节点变得“平滑”,Inkscape 使用什么算法(或公式)来计算控制点

也就是说,如果我有一个包含五个节点的路径,其 d 属性为

M 115.85065,503.57451
49.653441,399.52543
604.56143,683.48319
339.41126,615.97628
264.65997,729.11336

然后我将节点更改为平滑,d 属性更改为

M 115.85065,503.57451 
C 115.85065,503.57451 24.747417,422.50451
49.653441,399.52543 192.62243,267.61777 640.56491,558.55577
604.56143,683.48319 580.13686,768.23328 421.64047,584.07809
339.41126,615.97628 297.27039,632.32348 264.65997,729.11336
264.65997,729.11336

显然,Inkscape 计算控制点坐标(C 上或之后的行上倒数第二个和最后一个坐标对)。我对 Inkscape 使用的算法很感兴趣。

最佳答案

我在Inkscape的源码树下找到了对应的一段代码src/ui/tool/node.cpp,方法Node::_updateAutoHandles:

void Node::_updateAutoHandles()
{

// Recompute the position of automatic handles.
// For endnodes, retract both handles. (It's only possible to create an end auto node
// through the XML editor.)
if (isEndNode()) {
_front.retract();
_back.retract();
return;
}

// Auto nodes automaticaly adjust their handles to give an appearance of smoothness,
// no matter what their surroundings are.
Geom::Point vec_next = _next()->position() - position();
Geom::Point vec_prev = _prev()->position() - position();
double len_next = vec_next.length(), len_prev = vec_prev.length();
if (len_next > 0 && len_prev > 0) {
// "dir" is an unit vector perpendicular to the bisector of the angle created
// by the previous node, this auto node and the next node.
Geom::Point dir = Geom::unit_vector((len_prev / len_next) * vec_next - vec_prev);
// Handle lengths are equal to 1/3 of the distance from the adjacent node.
_back.setRelativePos(-dir * (len_prev / 3));
_front.setRelativePos(dir * (len_next / 3));
} else {
// If any of the adjacent nodes coincides, retract both handles.
_front.retract();
_back.retract();
}
}

关于svg - inkscape 如何计算 "smooth edges"的控制点坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13037606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com