[cairo] Algorithm help please!

Donn donn.ingle at gmail.com
Fri May 8 04:13:31 PDT 2009

Hello, I hope someone can give me a hand.

I am using Python-Cairo and drawing a path which I want to use as a 'track' 
for another object to follow along in a loop.

I have been using :
ctx.set_tolerance(1) # Suspect this will help in new algorithm...
pathfunc(ctx) # Draw a path of some kind
path = ctx.copy_path_flat() # get a list of tups with no curve_to's

So, I get a bunch of nodes (path) something like so:
(0, (0.0, 0.0))
(1, (25.0, 0.0))
(1, (27.51953125, 10.771484375))
(1, (33.90625, 23.359375))
(1, (51.25, 48.125))
(1, (62.96875, 62.578125))
(1, (63.37158203125, 63.206787109375))
(1, (62.32421875, 62.275390625))
(1, (55.0, 55.0)) *
(1, (0.0, 55.0)) *
(0, (0.0, 0.0))

This has two problems:
1. Where the line is straight (has only two nodes; marked * in list above) 
there are no nodes 'during' that section of the line -- so 
anything 'following' the path simply jumps from one end to the other.

2. I am working with a key-frame system. Let's say the number of nodes is 
nnodes. The number of keyframes is nkeys. 
If nkeys > nnodes the problem is that there are not *enough* nodes in that 
horrible tuple-list for the object to stop at along the way around the path.

So, the questions is: How can one divvy-up a path into nkeys number of nodes 
that will distribute evenly along the whole length?
(The greater nkeys, the more high-res the path, the smoother the following 
along the path will be.)

I have been googling and hacking, but not getting very far.

Right, hope that explained the problem.

Where I web: http://otherwise.relics.co.za/
Comics, tutorials, software and sundry

More information about the cairo mailing list