How to store all points in CGContextAddArc (CGContextRef) until NSMUtableArray

How can I split the whole pixel point in CGContextAddArc on NSMutableArray.or CGContextRef on NSMutable Array

static inline float radians(double degrees) { return degrees * PI / 180; } - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect parentViewBounds = self.bounds; CGFloat x = CGRectGetWidth(parentViewBounds)/2; CGFloat y = CGRectGetHeight(parentViewBounds)/2; UIColor *rbg=[UIColor redColor]; CGContextSetFillColor(context, CGColorGetComponents( [rbg CGColor])); CGContextMoveToPoint(context, x, y); CGContextAddArc(context, x, y,100,radians(35),radians(105),0); CGContextClosePath(context); CGContextFillPath(context); // here I want to store All points Containing in the Arc to NSMutableArray NSMutableArray *pointsArray=???? } 

IMAGE enter image description here

+6
source share
2 answers

Save or when you want to add points to the array of your CGPoint in NSValue,

 NSValue *point = [NSValue valueWithCGPoint:CGPointMake(your_X, your_Y)]; [pointsArray addObject:point]; 

Now, at a point in time, as you read CGPoint from an NSVaule string in an array,

 NSValue *getPoint = [pointsArray objectAtIndex:i]; CGPoint thePoint = [getPoint CGPointValue]; 

thePoint will be your answer.

0
source

Musthafa, you have several different problems here.

The first thing you are probably doing wrong. To check if the user has clicked on an arc, you are probably better off creating a path with an arc (CGPathAddArc) and then using CGPathContainsPoint.

Then you want to be sure that the arc really is what you want, it will not look like a pie, the arc is a section on the outside of the pie, and the closure will connect the ends of it, to form the pie you need to move to the center and from the center.

If you are trying to get points in a closed arc, the only way to do this is to create a CGBitmapContext and then display the path to CGContext and then CGBitmapContextGetData to get the backup data. You can then iterate to get the given values ​​and add them to your NSMutableArray, as iHungry suggested.

I can also ask the question why you want to use them in a mutable array, because if you repeat them for touch testing, it can be quite slow, it is better to leave them in a bitmap :)

0
source

Source: https://habr.com/ru/post/920284/


All Articles