一千萬個為什麽

搜索

用CoreGraphics查找二次貝塞爾的最小值/最大值

我正在使用CoreGraphics繪制二次貝塞爾曲線,但想計算曲線的最小值/最大值。我不是從數學背景出發的,所以這變得有點麻煩。有沒有人有關於如何解決這個問題的文章或想法?

最佳答案

對於一個二次Bezier來說,這實際上很簡單。

將您的三個控制點定義為 P0 =(x0,y0),P1 =(x1,y1)和 P2 =(x2,y2) 。要找到 x 中的極值,請求解這個等式:

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

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)

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查找二次貝塞爾的最小值/最大值