1
votes

I am trying to draw a chainsaw (just the blade) with ios core graphics, but getting stuck at a point, so far I've drawn something like this:

enter image description here

It looks ugly but I was just trying to see if I can draw one, and then do proper finishing later. The issue is that I can draw the teeth on the top and bottom flat sides but I have no idea how to draw the teeth around the curved corners. I've drawn the ellipse myself so I know where the coordinates are for the flat surfaces, but I don't know how to calculate the round corners. My questions are:

  1. Is there an easy way to draw the teeth on the rounded corners ?

  2. Is there a totally different and much better way to draw something like this in core graphics ?

  3. The last question is regarding animating the chainsaw. I was hoping that if I can finish the drawing, then I can use a timer and redraw the teeth again with an offset, and then alternate between the two drawings to give a moving effect. Would that be the right way to go, or is it not worth doing such animation using core graphics and using something like an animated gif would be a better way ?

I am new to core graphics so don't know much details. I can imagine that there are multiple ways to achieve what I am doing, but what I mean when I say "is it the right way to do this" is it one of the right ways to do this, or I am going down a completely wrong path. Thanks !

1
This seems like an elementary trigonometry question and not a programming question. Are you having trouble with the trig.? All you really need to know is sin(angle) = opposite/hypotenuse. cos(angle) = adjacent/hypotenuse. tan(angle) = opposite/adjacent. - Victor Engel

1 Answers

0
votes

(1) Drawing teeth around the rounded corner is a matter of identifying the points of the teeth. Consider that the inner-facing points of three teeth will fall along the rounded corner at angles: 1/8pi, 3/8pi, 5/8pi and 7/8pi.

The outer-facing points of those same three teeth will fall on a circle concentric to the rounded corner with a larger radius (larger by the height of a tooth). Those will fall at 1/4pi, 1/2pi and 3/4pi. The same idea can be reflected to the x<0 rounded corner on the left side. (or maybe not, maybe that side will be the chain saw's rectangular motor).

(2) I can't think of a totally different, much better way to do the drawing, except to point out that it could be done more realistically with an image (at least the static part).

(3) Probably wouldn't use a timer explicitly. I think the right way to go would be to place the chain on it's own CAShapeLayer. Have two (or more) chain paths (offset by some small phase shift in the placement of the teeth points). Add a repeating CABasicAnimation to the layer which alternates between the two paths.