How can store all points in the CGContextAddArc (CGContextRef) to NSMUtableArray
Asked Answered
S

2

6

How can i strore all pixel point in the CGContextAddArc To NSMutableArray.or CGContextRef to 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=????
        }

IMAGEenter image description here

Sponger answered 12/7, 2012 at 4:48 Comment(4)
Do you want store CGPoints i.e pixel location in NSMutableArray?Pashto
i think you get one point here, i.e point = (x,y). Am i right?Rinarinaldi
No,i Want to check User touch point is containing in the Arc or notSponger
What do you mean by “all points”? Do you mean the control points of the bezier curves?Moschatel
P
0

Store or when you want to add points in array your CGPoint in NSValue,

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

Now At retrieve time, how will be you read CGPoint from NSVaule stroe in array,

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

thePoint will be your answer.

Pashto answered 12/7, 2012 at 5:5 Comment(4)
from CGContextRef i want all points or( CGContextAddArc points)Sponger
i Want to check User touch point is containing in the Arc or notSponger
@MUSTHAFA did you get any solutions of your question?Jennee
@MUSTHAFA yes I need sample one.Can you please answer it here.Jennee
G
0

Musthafa, you have a few different issues here.

The first point is that you're probably going about this the wrong way. For checking if the user has clicked in an arc you're probably better creating a path with the arc ( CGPathAddArc) and then using CGPathContainsPoint.

Next, you want to be sure that an arc is really what you want, this won't look like a pie, the arc is the section on the outside of the pie, and the close will connect the ends of that, for a pie shape, you need to move to and from the centre.

If you're trying to get the points in the closed arc, the only way I can think of doing this is to create a CGBitmapContext and then render the path to the CGContext and then CGBitmapContextGetData to get the backing data. You can then iterate through this to get the set points and add them to your NSMutableArray as iHungry suggested.

I might also question why you want to stick them in a mutable array, since if you're iterating through them for touch testing, it could get pretty slow, better to leave them in the bitmap :)

Globose answered 12/7, 2012 at 7:42 Comment(2)
what am trying , when the user Touch particular Sector in the Pie Chart i want to pop up some View/Label Regarding about that view.See i update my QuestionSponger
Don't bother storing the points. Create the CGPathRef as you are, but add a close path to the arc (CGPathCloseSubpath). Save the CGPathRef in a property ( and don't forget to CGPathRelease it, ARC doesn't work for CG stuff) in your click action method, use CGPathContainsPoint(CGPathRef)Globose

© 2022 - 2024 — McMap. All rights reserved.