与SKPATH(Skia Sharp)获得二次Bezier线的中心点

发布于 2025-01-23 15:56:17 字数 261 浏览 4 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心↖ 2025-01-30 15:56:17

二次bezier具有一个非常简单的参数公式来计算躺在上面的点,您可以在许多地方找到它,例如 https://en.wikipedia.org/wiki/b%C3%A9ZIER_CURVE

“

根据您的问题的描述想要计算B(0.5),因为曲线长度(P0 ,B(0.5))和(B(0.5),P2 )是非对称贝齐尔的不同。
我要做的是:

  1. 将曲线扁平到具有任意精度p的多线线(选择所有t params,以便每3个连续t,以便:t k < t k+ 1 < sub> k+1 )&lt
  2. ; = l(p 0 ,...,p2 )/2< l(b(t k+1 ),...,p2 ),其中l是polyline的长度。
  3. 现在,有了发现K,我们知道我们的中点T 中间实现Tk < = t 中间中间< T K+1 。这可以再次以任意精度计算。

对于任何更高的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

Bezier formula

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:

  1. Flatten the curve to a polyline with an arbitrary precision p (selecting all the t params so that for every 3 consecutive t such that: tk < tk+1 < tk+2 distance between line (Pk, Pk+2) and point B(tk+1) < p)
  2. Find k such that: L(P0, ..., B(tk)) <= L(P0,..., P2)/2 < L(B(tk+1), ..., P2), where L is the length of polyline.
  3. Now with found k we know our middle point tmid fulfills tk <= tmid < tk+1. This can again be computed with an arbitrary precision.

For any higher degree Beziers you can use de Casteljau algorithm to calculate points for any given 0 <= t <= 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文