本文介绍了使用CoreGraphics查找二次贝塞尔曲线的最小值/最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CoreGraphics绘制二次贝塞尔曲线,但想计算曲线的最小/最大值.我不是来自数学背景,所以这有点麻烦.有人对解决此问题有任何文章或想法吗?

I am using CoreGraphics to draw a quadratic bezier but want to computer the min/max value of the curve. I am not from a mathematical background so this has become a bit troublesome. Does anyone have any articles or ideas about how to solve this?

推荐答案

对于二次贝塞尔曲线,这实际上很简单.

For a quadratic Bezier, this is actually quite simple.

将三个控制点定义为P0 = (x0,y0)P1 = (x1,y1)P2 = (x2,y2).要在x中找到极值,请求解以下方程:

Define your three control points as P0 = (x0,y0), P1 = (x1,y1) and P2 = (x2,y2). To find the extrema in x, solve this equation:

t = (x0 - x1) / (x0 - 2*x1 + x2)

如果为0 <= t <= 1,则在t处评估曲线并将位置存储为Px.对y做同样的事情:

If 0 <= t <= 1, then evaluate your curve at t and store the location as Px. Do the same thing for y:

t = (y0 - y1) / (y0 - 2*y1 + y2)

同样,如果为0 <= t <= 1,则在t处评估曲线并将位置存储为Py.最后,找到包含P0P2Px(如果找到)和Py(如果找到)的与轴对齐的边界框.此边界框还将紧密约束2D二次Bezier曲线.

Again, if 0 <= t <= 1, evaluate your curve at t and store the location as Py. Finally, find the axis-aligned bounding box containing P0, P2, Px (if found) and Py (if found). This bounding box will also tightly bound your 2D quadratic Bezier curve.

这篇关于使用CoreGraphics查找二次贝塞尔曲线的最小值/最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 00:20