views:

1263

answers:

4

Hi,

I have made a quad curve path using the method CGPathAddQuadCurveToPoint. I got the path perfectly. But, I want to know all the coordinate points which are participated in the path.

Is there a way to retrieve all the coordinate points in a path?

If not do u have any other solution for retrieving all the points in a curve mathematically.

Thanks in advance, Vamshi

+1  A: 

A quadratic curve is just that -- a curve. It's impossible to get a list of all of the points on it because there are infinitely many points, and it's not a simple line segment.

See Getting Information about Quartz Paths for a list of the functions you can use to query a CGPath object. Unfortunately, it seems like the most useful information you're going to get is with CGPathContainsPoint(), which only tells you if a given point is contained within the area of the path.

Adam Rosenfield
Thanks for the reply.. I have used the CGPathContainsPoint(). For using this method, we definitely need our path to be closed. But, in my case if I close the path then I will not get the expected path. If it we want to find all the points in between two points (it becomes a straight line) then there is a solution using Maths equations.Is there any solution for curves using Maths equations or any algorithm
A: 

If you want to work on the moveto, lineto, and curveto elements of the path, use CGPathApply. You pass this a pointer to a function in your program, and it calls that function once per element of the path.

Unfortunately, there's no way to just ask for each element like there is with AppKit's NSBezierPath. The function is the only way.

If you want to determine every pixel intersected by the path, too bad—that's not practical, and I can't even think of why you'd want that information. Some contexts, such as PDF contexts, don't even have pixels; in those cases, any question involving pixels is a non sequitur.

Peter Hosey
A: 

If not do u have any other solution for retrieving all the points in a curve mathematically.

What do you need them for, i.e. what problem are you trying to solve? If it is to intersect two curves, you can do this mathematically. Just set the two curve equations equal to each other and solve for the unknown.

Alex Reynolds
Thanks for the reply.. I am having a prob where I want to move an object(eg. Person) on the path. I can use CAKeyFrameAnimation to solve my problem wherer it needs the duration. But, I dont have duration in my case. While the object is moving I have to do some other operations on object like jumping or moving back etc. So, if I knw all the points on the path then I can make him to move on the points which will satisfy my requirement.
I don't understand the problem fully, but perhaps making your path time-based will help you solve this. That is, at t=0, the path equation puts the object at (x0, y0). At t=1, the path puts the object at (x1, y1). And so forth. Then, you do not need to remember all points, but simply calculate the (xi, yi) for time point t=i.
Alex Reynolds
A: 

I guess you're after something equivalent to the Java2D FlatteningPathIterator class. For example Java2D's path.getPathIterator(null, 1.0) returns an iterator of only 'lineTo' segments even if the original path had curveTo and quadTo, the double argument controls the 'flatness', giving you an easy way to calculate any point on the curve. I'm searching for the same thing in Cocoa, but have found nothing. If you find a solution please let me know. There are curve implmentations around (e.g. http://sourceforge.net/projects/curves/) that could be ported, but there's always a risk that if you don't use the same algorithm as Cocoa then there could be errors between your interpolation and the stroked NSBezierPath/CGPath.