We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Retrieving arbitrary coords along Curve()
Page Index Toggle Pages: 1
Retrieving arbitrary coords along Curve()? (Read 567 times)
Retrieving arbitrary coords along Curve()?
Jan 28th, 2006, 5:45pm
 
I'm looking for an algorithm to compute many points along a smooth curve defined by several points (a la the curve() function in processing.core()).  I'd just use that curve function, but I want to use the points to generate a series of quads that I can slap a texture on, so I need finer control than just "slap a curve on the canvas."

Is there a simple way to define several points on the canvas, calculate the coordinates of several intermediate points, and the normal vector of the curve at those points?

I'm looking through the core source from subversion right now, and I'm having a hard time singling out the algorithm that actually calculates the curves -- I think it involves the matrices but I don't know enough about this sort of math to work it out..
Re: Retrieving arbitrary coords along Curve()?
Reply #1 - Jan 30th, 2006, 6:39pm
 
Check in the complete reference:

http://processing.org/reference/index_ext.html

they've got all of these:

Quote:
Curves
bezierTangent()
bezierDetail()
curveTightness()
bezierPoint()
curveDetail()
curvePoint()
curve()
bezier()


If you use beziers, then bezierPoint() and bezierTangent() should work.  For the curves I don't know, but a quick hack would be to use the vector from a point a little bit before and the point in question as a tangent.

curveTangent = normalized((curvePoint(t) - curvePoint(t-0.001)) + (curvePoint(t+0.001) - curvePoint(t)))

Don't really know if this would work, though it's maybe worth a try.  (of course this is just the algorithm, the code itself would be different)
Re: Retrieving arbitrary coords along Curve()?
Reply #2 - Jan 31st, 2006, 1:34am
 
I looked at the complete reference, and the latest Subversion source, before posting, and it looks like bezierTangent, in particular, is currently nonfunctional (check the source -- there's a frustrated-sounding comment in there). Otherwise, it looks like a workable solution.. Thanks Smiley
Page Index Toggle Pages: 1