CGPathAddCurveToPoint的参数是什么意思? [英] What do the parameters to CGPathAddCurveToPoint mean?
问题描述
我想根据太阳在一天中不同时间点的坐标以编程方式构建一个 CGPathRef
。计算积分不是问题,但我想制作一个平滑的 CGPathRef
,并认为 CGPathAddCurveToPoint
是合适的。
I want to build a CGPathRef
programatically based on the coordinates of the Sun at different points of the day. Calculating the points is not a problem, but I want to make a CGPathRef
that is smooth and thought CGPathAddCurveToPoint
would be appropriate.
我理解路径,变换,x和y参数,但我不确定其他参数。根据Apple文档,它们是控制点,我猜它们就像你在矢量绘图程序中看到的那样,你可以调整曲线通过点的方式。
I understand the path, transform, x and y parameters, but I'm not sure about the others. Per the Apple documentation they are the control points, and I'm guessing they are like you'd see in a vector drawing program where you can adjust the way the curve passes through the point.
我的问题是如何在不知道这些坐标提前的情况下选择与我的坐标相关的点?我想也许只是从每个第一个控制点中减去一个设定的数量,并将相同的数量添加到第二个控制点,但这听起来过于简化。是否有一种标准方法可以生成对于平滑曲线有意义的控制点?
My question is how to choose points that relate to my coordinates without knowing what those coordinates are ahead of time? I'm thinking maybe just subtract a set amount from each of the first control points and add the same amount to the second control points, but that sounds over simplified to me. Is there a standard method for generating control points that "make sense" for a smooth curve?
void CGPathAddCurveToPoint (
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cp1x,
CGFloat cp1y,
CGFloat cp2x,
CGFloat cp2y,
CGFloat x,
CGFloat y
);
推荐答案
额外的点是曲线的bezier控制点超出源(当前)点和曲线到目标点(参见 http:// en.wikipedia.org/wiki/Bézier_curve获得一般性解释)。行currentX,currentY - cp1x,cp1y是当前点的向量'out',cp2x,cp2y - x,y是最后一点的向量'in'。
The extra points are the bezier control points for the curve out of the source (current) point and the curve into the target point (see http://en.wikipedia.org/wiki/Bézier_curve for a general explanation). The line currentX,currentY - cp1x,cp1y is the vector 'out' of the current point and cp2x,cp2y - x,y is the vector 'in' to the final point.
从p1到p2产生平滑曲线的合理方法(假设4点p0,p1,p2,p3)是(伪代码):
A reasonable way to produce a smooth curve from p1 to p2 (assuming 4 points p0,p1,p2,p3) is (pseudocode):
v = (strength of curve from 0.0 to 1.0)
cp1x = p1.x+v*(p1.x-p0.x)
cp1y = p1.y+v*(p1.y-p0.y)
cp2x = p2.x-v*(p3.x-p2.x)
cp2y = p2.y-v*(p3.y-p2.y)
对于起点,将cp1x,cp1y设置为起始点x,y,并设置为结束点集cp2x,cp2y到结尾x,y。
For the starting point, set cp1x,cp1y to the starting x,y and for the ending point set cp2x,cp2y to the ending x,y.
注意:我已经更新了答案以纳入来自ughoavgfhw的评论
NOTE: I've updated the answer to incorporate the comments from ughoavgfhw
这篇关于CGPathAddCurveToPoint的参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!