CGPathAddCurveToPoint 的参数是什么意思?

发布于 2024-10-07 09:22:23 字数 555 浏览 10 评论 0 原文

我想根据一天中不同时间点的太阳坐标以编程方式构建一个 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
); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-10-14 09:22:23

额外的点是从源(当前)点出发的曲线和进入目标点的曲线的贝塞尔控制点(请参见 http://en.wikipedia.org/wiki/Bézier_curve 获取一般说明)。线 currentX,currentY - cp1x,cp1y 是当前点的“出”向量,cp2x,cp2y - x,y 是到最终点的“入”向量。

产生从 p1 到 p2 的平滑曲线(假设有 4 个点 p0,p1,p2,p3)的合理方法是(伪代码):

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。

注意:我已经更新了答案以纳入 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):

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)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文