[cairo] Algorithm help please!

Gerdus van Zyl gerdusvanzyl at gmail.com
Fri May 8 04:58:37 PDT 2009


I wrote some quick code, see if it helps: http://python.pastebin.com/f2e4d0193
My thought is that you need to insert nodes between the cairo nodes
based on the distance between the points till it equals nkeys. So far
I know you can't do something like that in cairo's public api.

~Gerdus

On Fri, May 8, 2009 at 1:13 PM, Donn <donn.ingle at gmail.com> wrote:
> 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.
> \d
>
> --
> Where I web: http://otherwise.relics.co.za/
> Comics, tutorials, software and sundry
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list