绘制Bezier曲线的部分(Drawing sections of a Bezier curve)

编程入门 行业动态 更新时间:2024-10-22 13:49:58
绘制Bezier曲线的部分(Drawing sections of a Bezier curve)

我正在编写代码来将一个四分之一椭圆逼近Bézier曲线 。

现在已经完成了,我在绘制这条曲线的部分时遇到了麻烦。 我需要一些帮助选择控制点。

最初,我已将控制点距离与曲线起点距离的比率设为0.51。

编辑:

pseudo code import cairo [...] ctx.moveto(0,y1) ctx.curveto(0,y1/2,x1/2,0,x1,0)

这将导致从(0,y1)到(x1,0)的近似椭圆曲线,椭圆中心在(x1,y1)处。

注意扫描的参数角是pi/2 。 如果我想把它画成更像虚线的图案,那我该怎么做? 例如,从t = pi/6到t = pi/3 ? 我如何选择控制点?

I was writing code to approximate a quarter ellipse to a Bézier curve.

Now having done that, I am encountering trouble drawing sections of this curve. I need some help choosing the control points.

Initially, I had taken the ratio of distance of control point to distance of start of curve as 0.51.

Edited:

pseudo code import cairo [...] ctx.moveto(0,y1) ctx.curveto(0,y1/2,x1/2,0,x1,0)

This will result in an approximately elliptical curve from (0,y1) to (x1,0) with the ellipse center at (x1,y1).

Notice the parametric angle swept is pi/2. If suppose I wish to draw it in sections more like a dashed pattern, then how do I do it? For example, from t = pi/6 to t = pi/3? How do I choose the control points?

最满意答案

要使用单个三次方圆弧近似四分之一圆弧,通常所做的就是使中点完全位于圆上并使用相切的开始和结束方向。

这在任何合理的度量标准中都不是正式的“最佳”近似值,但是非常容易计算......例如,圈四分之一的幻数是0.5522847498 。 看到这个页面的一些细节...

要绘制一个椭圆弧,您可以拉伸圆弧的控制点(再次不是数学上称为“最佳逼近”的东西)。

通用角度的情况

这个定义下的通用角度的最佳弧度(即,使贝塞尔曲线的中点位于弧的中间)可以使用以下方法计算...

1.对称三次贝塞尔弧的最大高度为3/4 H,其中H是控制点的高度

考虑如何用De Casteljau算法或我的答案计算贝塞尔曲线的计算来计算贝塞尔三次方的中点,这应该很清楚; 另请参见下图:

对称Bezier立方弧的中点高度

y_mid = ((0+H)/2 + (H+H)/2) / 2 = 3/4 H


2.圆心的中心角度是基座角度的两倍

查看任何基本几何文本的证明。


最后命名 L为极值之间的距离, S为对称Bezier的(未知)控制臂, 2*alpha为近似圆的角度,我们可以计算

3. S = L(2/3)(1-cosα)/(sinα** 2)

这是从上面的等式和一些计算得出的; 请参阅下面的图片了解说明。

控制点距离计算

To approximate a circle quarter using a single cubic arc what is normally done is making the middle point being exactly on the circle and using tangent starting and ending directions.

This is not formally the "best" approximation in any reasonable metric but is very easy to compute... for example the magic number for a circle quarter is 0.5522847498. See this page for some detail...

To draw an ellipse arc instead you can just stretch the control points of the circular arc (once again not something that would qualify mathematically as "best approximation").

The generic angle case

The best arc for a generic angle under this definition (i.e. having the middle point of the bezier being on the middle of the arc) can be computed using the following method...

1. The maximum height of a symmetrical cubic bezier arc is 3/4 H where H is the height of the control point

This should be clear considering how the middle point of a bezier cubic is computed with the De Casteljau's algorithm or my answer about explicit computation of a bezier curve; see also the following picture:

Height of midpoint of a symmetric Bezier cubic arc

y_mid = ((0+H)/2 + (H+H)/2) / 2 = 3/4 H


2. The angle at the center for a circle cord is twice the angle at the base

See any elementary geometry text for a proof.


Finally naming L the distance between the extremes, S the (unknown) control arm of the symmetric Bezier, 2*alpha the angle of circle to approximate we can compute that

3. S = L (2/3) (1-cos(alpha)) / (sin(alpha)**2)

This follows from the above equations and from some computation; see the following picture for a description.

Control point distance computation

更多推荐

本文发布于:2023-08-07 02:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459000.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:曲线   Bezier   Drawing   curve   sections

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!