views:

391

answers:

1

Hi everyone. I'm fairly new to Quartz 2D.

Imagine the following scenario:

You have a circle-shaped mini map view. I'm drawing triangle (the arc isn't important right now) on top of the map. This shape represents the visible area.

I need to have the triangle shape rotate along the mini map as the user changes orientation.

Currently this how the path is being drawn:

CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);

CGPath visibleAreaPath = CGPathCreateMutable();

CGPathMoveToPoint(visibleAreaPath, &transform, miniMapCenter.x, miniMapCenter.y);
CGPathAddLineToPoint(visibleAreaPath, &transform, 18.0, 8.0);
CGPathAddLineToPoint(visibleAreaPath, &transform, 66.0, 8.0);

CGPathCloseSubpath(visibleAreaPath);

I then draw the path using a CAShapeLayer like so:

CALayer *rootLayer = [visibleAreaView layer];

visibleAreaShape = [CAShapeLayer layer];
[visibleAreaShape setFillColor:[UIColor colorWithHue:0.584 saturation:0.8 brightness:0.9 alpha:0.6].CGColor];
[visibleAreaShape setFillRule:kCAFillRuleNonZero];
[visibleAreaShape setAnchorPoint:CGPointMake(0.5, 0.5)];
[rootLayer addSublayer:visibleAreaShape];
[visibleAreaShape setPath:visibleAreaPath];

The path is being rotated, but not based on a given origin. Keep in mind that setting the layer's anchor point doesn't help me since what I want is to rotate the path (ultimately I wouldn't even need to display it, since I will be using it to determine which points are visible on the mini map).

Any ideas on how to accomplish this? Thank you.

A: 

I would suggest you store the points in polar form and convert to a path when needed. It's very easy to rotate in polar coordinates (simply change the theta value).

David Kanarek