I’m currently making an application which draws out a certain network of signs to the screen (on a CGContextRef). So far everything is going great, but now i’m finding myself in the situation that i can’t solve this problem:
I’m trying to draw an object dynamically knowing only the line its on (have the start and ending point’s x and y coordinates). With these i found the middle of the line, this is where the symbol should be drawn. With this information i found the angle of the line (with the top as 0). This is the information i have right now:
CGPoint firstLocation;
CGPoint secondLocation;
CGPoint middleLocation;
double x1 = firstLocation.x;
double y1 = firstLocation.y;
double x2 = middleLocation.x;
double y2 = middleLocation.y;
float a = (atan2(y2-y1, x2-x1) * (180/M_PI)) - 90;
I looked at using some transform function (like CGAffineTransform) on a CGRect, but this doesn’t seem to work as i need to rotate the rect around it’s center and a CGRect would only rotate around it’s origin.
I want to create the following symbols with the above information:

Any help is appreciated, and if you need any more information please tell me!
In my app I do something similar. I have a path that I add a transform to before drawing. The transform shifts the path to the midpoint, rotates it, and shifts it back:
You don’t have to use
CGPathAddLines, that was just the easiest way for me to construct the path. All of theCGPathAdd...functions can take a transform.If you’re not using
CGPath, you could do a similar transform in the context itself by doingCGContextTranslateCTMandCGContextRotateCTM.