How to create a perfect half circle with CGPathAddCurveToPoint?

南笙酒味 提交于 2019-12-06 08:22:50

问题


I am trying to create a perfect right half circle of 15 points radius with CGPathAddCurveToPoint, like this:

CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30);

It starts at the top middle of the circle. Then the first control point is set to the top right corner of the circle's bounding box. The second control point is set to the bottom right corner of the circle's bounding box. The circle ends at bottom middle of the bounding box.

But when drawn, the circle has an egg-like shape.

How can I make a perfect, flawless right semisphere starting at point 0,0 going to the right and ending at 0,30?


回答1:


CGPathAddCurveToPoint creates a Bézier curve, not a circular arc. The method you’re looking for is CGPathAddArc or CGPathAddArcToPoint, as below:

CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddArc(path, NULL, 0, 15, 15, M_PI_2, -M_PI_2, true);


来源:https://stackoverflow.com/questions/12012807/how-to-create-a-perfect-half-circle-with-cgpathaddcurvetopoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!