3

Possible Duplicate:
Circle to Circle Segment Collision

I am the beginner with iOS development. Do you know how to draw a image like this http://www.hoodshomecenters.com/product_images/v/723/QuarterRound__65714_zoom.jpg with CoreGraphic?

Community
  • 1
  • 1
Quang Pham
  • 31
  • 1
  • 2
  • You should first look if there are answers on Stackoverflow. http://stackoverflow.com/questions/4226356/circle-to-circle-segment-collision – Mundi Aug 31 '12 at 08:16

3 Answers3

12

This is the code for drawing the arc portion. Once it is drawn then you can draw lines within it.

#include <math.h>

CGFloat radius = 100;

CGFloat starttime = M_PI/6; //1 pm = 1/6 rad
CGFloat endtime = M_PI;  //6 pm = 1 rad

//draw arc
CGPoint center = CGPointMake(radius,radius);
UIBezierPath *arc = [UIBezierPath bezierPath]; //empty path
[arc moveToPoint:center];
CGPoint next;
next.x = center.x + radius * cos(starttime);
next.y = center.y + radius * sin(starttime);
[arc addLineToPoint:next]; //go one end of arc
[arc addArcWithCenter:center radius:radius startAngle:starttime endAngle:endtime clockwise:YES]; //add the arc
[arc addLineToPoint:center]; //back to center

[[UIColor yellowColor] set];
[arc fill];

You need to overwrite the drawRect method of the view in which you will be used for showing this drawing.

dda
  • 6,030
  • 2
  • 25
  • 34
Gypsa
  • 11,230
  • 6
  • 44
  • 82
2

You can draw an arc segment with the UIBezierPath class using the method bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise. Have a look here

You will also need to create a path for your lines using the combination of CGContextMoveToPoint/ CGContextAddLineToPoint

Last you stroke your lines by invoking the stroke method on your path.

EDIT To draw the inner lines you probably want to clip those: this is done with the CGContextClip function

tiguero
  • 11,477
  • 5
  • 43
  • 61
0

You can certainly use

void CGContextAddArcToPoint

The documentation:

CGContext reference

Resh32
  • 6,500
  • 3
  • 32
  • 40