开发者

iPhone - Drawing something at a given point using angle from center of view

开发者 https://www.devze.com 2023-04-01 13:43 出处:网络
I have a view with a point on its center. I have an angle in degrees (or radian, that\'s not the problem).

I have a view with a point on its center.

I have an angle in degrees (or radian, that's not the problem). I have a circle which center is the center of the view, and the radius is R.

I'd like to draw :

  • something (let's say an image) on the point that is placed on the circle, at an angle of R from the vertical position.

  • an arc from the vertical position abov开发者_开发百科e the center that intersect the circle, to that point

How may I do that ?


I think it you could calculate the image position with:

CGPoint center = self.view.center;
float x = radius * cos(angle);
float y = radius * sin(angle);

CGPoint newPoint = CGPointMake(center.x + x, center.y + y);

Let me know if it worked.

As for drawing an arc you would have two points, one is newPoint that is calculated above (on circle depending the angle) and point above the center intersecting the circle which is calculated easily:

CGPoint pointAboveCenter = CGPointMake(center.x, center.y + radius);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号