CGPath curve from points (iPhone) - iphone

I'm looking for a way to draw a curve (perhaps a parametric function?) into a CGContext
The best example which I can think of is the Adobe Ideas iPad application. As the user drags their finger, the application draws lines for every touchesMoved: using CGContextAddLineToPoint. After the user picks up their finger at touchesEnded:, the application does some math and replaces all of the lines with a single, smoothed curve.
What I have is a list of CGPoints, and I am looking to draw a smooth curve which follows those CGPoints into the CGContext.
Any assistance?

I'd advise creating a CGPathRef and use the CGPathAddQuadCurveToPoint method.
Hope this helps!

Related

SpriteKit - Draw Bezier Curve Gradually

I'm working on an iOS educational where kids are drawing letters. The game mechanism is pretty simple and works OK. What I want to do is to show a drawing progress by turning the elapsed part into green thick line. See the image:
There are couple of solution I have in mind.
Mask over hidden path which transforms according to users touch position
Creating a new path on touchesMoved: by taking the original and adding a point to the user touch position, then stripping the rest
What would you choose or is there some better solution?
Note: I want to draw the green path precisely as the dashed one. By just drawing a path following the user movement would result in ugly line.
Thanks.
I would say your choice depends on whether the dashed line is also drawn (or drawable in all of its parts) with bezier curves.
If the dashed line is an image you show, probably solution 1 with an also drawn thick line and an adapted mask is easiest to do.
If the dashed line is already drawn as a bezier curve (or drawn by drawing several connected bezier curves), then solution 2 seems best to me. The tricky part would be to ensure you exactly follow the dashed line in this case (but I suppose you figured that already :-).

Draw Curve on Touch Points in iPhone SDK

i want to draw curve with user touches two points perfectly...!but,no idea for this implementation for this functionality...!
Help with me any code or tutorial with greatly appreciated....!
Thanks...!
Look at apple's 'Drawing Shapes Using Bezier Paths' guid.

iOS OpenGL or CoreGraphics smooth rectangle drawing

I'm trying to draw a filled rectangle in the drawRect and the rotate it by 5 degrees. The problem is that when I rotate this rectangle, the edges look very jagged. I have the feeling that this needs some anti-alising (or something similar), but I can't find any good sources of more information.
Does anyone have a good hint?
It really isn't possible to have a nice, natural curve on a computer because if you look closely you will always see that it really isn't a curve, it's a jagged line of squares.
More answering your question, if you want your line to be softer, you could blur it with a CIFilter. Remember that when you rotate something by anything other than 90, 180, 270, or 360 degrees you will lose quality. Your rectangle doesn't need anti-aliasing until it's rotated, and I'm sure apple has written a beautifully complicated way to blend/antialias your context.
Probably the easiest way to do this is to draw the individual lines in your rect at the slant instead of rotate the rect after you draw it.

Bending an image

I want to bend a rod like image in response to user touches. The user should be able to change the curvature of the image using touches. How do you do this using Quartz? There is obviously no standard transform for this. I am having a tough time figuring the math for doing this.
You can’t do it using just an affine transform, which is by definition linear. You can draw the bar in many small chunks, slowly bending along the path, or use OpenGL to draw them along a tri-strip or quad-strip.

iPhone animation: how do I animate the filling up of an area?

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.
I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.
Thanks,
Sandeep
Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.