- #1
MaTHFRo
- 7
- 0
Hi all,
I'm currently writing an iPhone application where I'm taking the following ellipse which I created in Adobe Illustrator:
http://img29.imageshack.us/img29/6584/95436658.gif
And drawing it in my code using the following:
CGPathMoveToPoint(515.98, 258.24);
CGPathAddCurveToPoint(515.98, 435.61, 415.54, 515.98, 258.24, 515.98);
CGPathAddCurveToPoint(100.94, 515.98, 0.50, 435.61, 0.50, 258.24);
CGPathAddCurveToPoint(0.50, 80.86, 100.94, 0.50, 258.24, 0.50);
CGPathAddCurveToPoint(415.54, 0.50, 515.98, 80.86, 515.98, 258.24);
Where CGPathAddCurveToPoint draws a cubic bezier curve to a graphics path. The first four parameters for this function are the first and second control points respectively, and the last two parameters are the end point ie CGPathAddCurveToPoint(cp1x, cp1y, cp2x, cp2y, epx, epy). Each call to CGPathAddCurveToPoint draws one of the four curves that make up my ellipse. Also, CGPathMoveToPoint sets the starting point.
As you can see from above, the code draws the ellipse within a 515.98 x 515.98 square. What I'm trying to do is, I want my code to fit this ellipse (and stretch it) within any rectangular shape I give it. So I'll need to express the points I have up top in terms of the rectangular width and height of the given rectangle. This is easy enough to do for the end points. I am having trouble however figuring out how to express the control points in this manner. Would this be some proportion of the height or width? Any help would be appreciated.
I'm currently writing an iPhone application where I'm taking the following ellipse which I created in Adobe Illustrator:
http://img29.imageshack.us/img29/6584/95436658.gif
And drawing it in my code using the following:
CGPathMoveToPoint(515.98, 258.24);
CGPathAddCurveToPoint(515.98, 435.61, 415.54, 515.98, 258.24, 515.98);
CGPathAddCurveToPoint(100.94, 515.98, 0.50, 435.61, 0.50, 258.24);
CGPathAddCurveToPoint(0.50, 80.86, 100.94, 0.50, 258.24, 0.50);
CGPathAddCurveToPoint(415.54, 0.50, 515.98, 80.86, 515.98, 258.24);
Where CGPathAddCurveToPoint draws a cubic bezier curve to a graphics path. The first four parameters for this function are the first and second control points respectively, and the last two parameters are the end point ie CGPathAddCurveToPoint(cp1x, cp1y, cp2x, cp2y, epx, epy). Each call to CGPathAddCurveToPoint draws one of the four curves that make up my ellipse. Also, CGPathMoveToPoint sets the starting point.
As you can see from above, the code draws the ellipse within a 515.98 x 515.98 square. What I'm trying to do is, I want my code to fit this ellipse (and stretch it) within any rectangular shape I give it. So I'll need to express the points I have up top in terms of the rectangular width and height of the given rectangle. This is easy enough to do for the end points. I am having trouble however figuring out how to express the control points in this manner. Would this be some proportion of the height or width? Any help would be appreciated.
Last edited by a moderator: