我想根据一天中不同时间点的太阳坐标以编程方式构建一个 CGPathRef 。计算点不是问题,但我想制作一个平滑的 CGPathRef
,并且认为 CGPathAddCurveToPoint
会合适。
我了解路径、变换、x 和 y 参数,但我不确定其他参数。根据苹果文档,它们是控制点,我猜它们就像您在矢量绘图程序中看到的那样,您可以在其中调整曲线穿过点的方式。
我的问题是如何在不提前知道这些坐标的情况下选择与我的坐标相关的点?我想也许只需从每个第一个控制点中减去一定的量,然后向第二个控制点添加相同的量,但这对我来说听起来过于简单了。是否有一种标准方法来生成对平滑曲线“有意义”的控制点?
void CGPathAddCurveToPoint (
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cp1x,
CGFloat cp1y,
CGFloat cp2x,
CGFloat cp2y,
CGFloat x,
CGFloat y
);
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.
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
);
发布评论
评论(1)
额外的点是从源(当前)点出发的曲线和进入目标点的曲线的贝塞尔控制点(请参见 http://en.wikipedia.org/wiki/Bézier_curve 获取一般说明)。线 currentX,currentY - cp1x,cp1y 是当前点的“出”向量,cp2x,cp2y - x,y 是到最终点的“入”向量。
产生从 p1 到 p2 的平滑曲线(假设有 4 个点 p0,p1,p2,p3)的合理方法是(伪代码):
对于起点,将 cp1x,cp1y 设置为起始 x,y 并设置终点点cp2x,cp2y 到结尾 x,y。
注意:我已经更新了答案以纳入 ughoavgfhw 的评论
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.
A reasonable way to produce a smooth curve from p1 to p2 (assuming 4 points p0,p1,p2,p3) is (pseudocode):
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.
NOTE: I've updated the answer to incorporate the comments from ughoavgfhw