[英]how to draw curve with four points
I can draw a curve using bezier path, but instead of specifying two control points, I want to specify two points that the path go through it, shown as following 我可以使用贝塞尔曲线绘制一条曲线,但是我不想指定两个控制点,而是要指定路径经过它的两个点,如下所示
the startPoint is (10,90), end point is (70,70), and the curve pass (20, 50), which is the peak point. startPoint是(10,90),终点是(70,70),曲线通过(20,50),这是峰值。 and (60,100).
和(60,100)。 Please let me know how to draw it.
请让我知道如何绘制它。
From "Bézier curve" article in Wikipedia: 摘自Wikipedia中的“贝塞尔曲线”:
Any series of any 4 distinct points can be converted to a cubic Bézier curve that goes through all 4 points in order.
任何4个不同点的任何序列都可以转换为三次Bézier曲线,该曲线按顺序遍历所有4个点。 Given the starting and ending point of some cubic Bézier curve, and any two other distinct points in sequence along that curve, the control points for the original Bézier curve can be recovered.[3]
给定某些三次贝塞尔曲线的起点和终点,以及沿该曲线的顺序的其他两个不同点,就可以恢复原始贝塞尔曲线的控制点。[3]
and at the end follows link to http://people.sc.fsu.edu/~jburkardt/html/bezier_interpolation.html 最后是指向http://people.sc.fsu.edu/~jburkardt/html/bezier_interpolation.html的链接
You can use UIBezierPath 's addCurveToPoint:controlPoint1:controlPoint2: method. 您可以使用UIBezierPath的 addCurveToPoint:controlPoint1:controlPoint2:方法。
CGPoint startPt, endPt, cPt1, cPt2;
// init points here
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPt];
[path addCurveToPoint:endPt controlPoint1:cPt1 controlPoint2:cPt2];
Assuming we have four points D0(x0,y0)
, D1(x1,y1)
, D2(x2,y2)
, D2(x3,y3)
. 假设我们有四个点
D0(x0,y0)
, D1(x1,y1)
, D2(x2,y2)
, D2(x3,y3)
。 We have to find Bezier cubic spline P0-P1-P2-P3
passing through D0
, D1
, D2
and D3
. 我们必须找到穿过
D0
, D1
, D2
和D3
Bezier三次样条P0-P1-P2-P3
。
Obviously, 明显,
P0 = D0
P3 = D2
Then there are infinite number of Bezier splines passing through point D1
and point D2
defined by equations 然后有无数的贝塞尔曲线样条线通过等式定义的
D1
点和D2
点
P2 = (D1 - (1-t1)^3 * P0 - t1^3 * P3) / (3*(1-t1)*t1^2) -
(1-t1) * P1/t1;
P2 = (D2 - (1-t2)^3 * P0 - t2^3 * P3) / (3*(1-t2)*t2^2) -
(1-t2) * P1/t2;
where t1
is Bezier curve parameter corresponding to point D1
and t2
is corresponding parameter of D2
. 其中
t1
是与点D1
对应的贝塞尔曲线参数, t2
是D2
对应参数。
Solving this system of equations will give us P1
解决这个方程组将给我们
P1
P1 = t2*(D1 - (1-t1)^3 * P0 - t1^3 * P3) / (3*(1-t1)*t1*(t2-t1)) -
t1*(D2 - (1-t2)^3 * P0 - t2^3 * P3) / (3*(1-t2)*t2*(t2-t1));
We still need to define t1
and t2
. 我们仍然需要定义
t1
和t2
。 Their values can be pretty much anything as long as they are not equal and not equal to 1
. 只要它们不相等且不等于
1
它们的值几乎可以是任何值。 One obvious choice is 0.25
and 0.75
. 显而易见的选择是
0.25
和0.75
。
Here is a resulting curve for a set of random input values 这是一组随机输入值的结果曲线
Then P1
and P2
can be used as controlPoint1 and controlPoint2 in UIBezierPath's addCurveToPoint:controlPoint1:controlPoint2 method. 然后,
P1
和P2
可以用作UIBezierPath的addCurveToPoint:controlPoint1: controlPoint2方法中的controlPoint1和controlPoint2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.