与SKPATH(Skia Sharp)获得二次Bezier线的中心点
我在skpath
上使用Quadto
-Method绘制bezier行。我的要求是要在渲染的Bezier线上获得一个或多或少在线中间的渲染行。我使用此点在线上显示标签,并提供了与线路交互的热点。
当前,我制作了一种简单的算法,该算法试图解决行Vie getFillPath
的点,然后尝试检测到最接近bezier的开始和结束的思想直线中心的点。
但是,这感觉很残酷。是否有更复杂的方法可以满足我的要求?
I draw Bezier Lines with the QuadTo
-Method on a SKPath
. My requirement is to get a point on the rendered Bezier Line which is more or less in the middle of the line. I use this point to show a label on the line and to provide a hit point to interact with the line.
Currently, I shoehorned a simple algorithm which tries to resolve the points of the line vie GetFillPath
and then try to detect the point which is nearest to the center of a thought straight line from the Bezier’s start and end.
This works, however, it feels extremely brutish. Is there a more sophisticated way to fulfill my requirement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
二次bezier具有一个非常简单的参数公式来计算躺在上面的点,您可以在许多地方找到它,例如 https://en.wikipedia.org/wiki/b%C3%A9ZIER_CURVE
根据您的问题的描述想要计算B(0.5),因为曲线长度(P0 ,B(0.5))和(B(0.5),P2 )是非对称贝齐尔的不同。
我要做的是:
对于任何更高的beziers,您都可以使用de Casteljau算法来计算任何给定0< = t< = 1的点。
The quadratic Bezier has a pretty simple parametric formula to calculate points lying on it, you can find it in many places, e.g. https://en.wikipedia.org/wiki/B%C3%A9zier_curve
As per description of your problem it is important to notice, that you don't specifally want to calculate the point B(0.5), as the length of curves (P0, B(0.5)) and (B(0.5), P2) can be different for non-symmetric Beziers.
What I would do is:
For any higher degree Beziers you can use de Casteljau algorithm to calculate points for any given 0 <= t <= 1.