From e6db5bbb638339f00e211f3f47f5838b135a0e75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Tue, 16 May 2006 15:47:55 +0000 Subject: [PATCH] some more introductory path examples git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@2664 069f4177-920e-0410-937b-c2a4a81bcd90 --- examples/path/INDEX | 2 ++ examples/path/arclen.py | 11 +++++++++++ examples/path/arclen.txt | 13 +++++++++++++ examples/path/at.py | 20 ++++++++++++++++++++ examples/path/at.txt | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 examples/path/arclen.py create mode 100644 examples/path/arclen.txt create mode 100644 examples/path/at.py create mode 100644 examples/path/at.txt diff --git a/examples/path/INDEX b/examples/path/INDEX index 62bcd8ab..bd7be14e 100644 --- a/examples/path/INDEX +++ b/examples/path/INDEX @@ -1,4 +1,6 @@ addjoin +arclen +at circles springs knot diff --git a/examples/path/arclen.py b/examples/path/arclen.py new file mode 100644 index 00000000..59ca5052 --- /dev/null +++ b/examples/path/arclen.py @@ -0,0 +1,11 @@ +from pyx import * + +c = canvas.canvas() + +p1 = path.curve(0, 0, 1, 0, 1, 1, 2, 1) +p2 = path.line(0, 0, p1.arclen(), 0) +c.stroke(p1) +c.stroke(p2) + +c.writeEPSfile("arclen") +c.writePDFfile("arclen") diff --git a/examples/path/arclen.txt b/examples/path/arclen.txt new file mode 100644 index 00000000..1564a20e --- /dev/null +++ b/examples/path/arclen.txt @@ -0,0 +1,13 @@ +Arc length of a path + +In this example we use the `arclen` method of the path instance `p1` to get the +arc length and create a straight line `p2` with the same arc length. ... + +! While here we use the return value of the arc length as a parameter to a path +constructor, you might be interested in what kind of object the return value of +the `arclen` method call really is: It is a PyX length in true coordinates, +since the path already analyses the PyX units and the return value thus needs +to be fixed and can not be scaled anymore. Printing the result of the `arclen` +method call of path `p1` would show you: + + (0.023110 t + 0.000000 u + 0.000000 v + 0.000000 w + 0.000000 x) m diff --git a/examples/path/at.py b/examples/path/at.py new file mode 100644 index 00000000..9c961a8e --- /dev/null +++ b/examples/path/at.py @@ -0,0 +1,20 @@ +from pyx import * + +def mark(x, y): + return path.circle(x, y, 0.1) + +c = canvas.canvas() + +p1 = path.curve(0, 0, 1, 0, 1, 1, 2, 1) +c.stroke(p1) +c.fill(mark(*p1.atbegin())) +c.fill(mark(*p1.at(0.5*p1.arclen()))) +c.fill(mark(*p1.atend())) + +p2 = path.curve(3, 0, 4, 0, 4, 1, 5, 1) +c.stroke(p2) +c.fill(mark(*p2.at(p2.begin()+0.5))) +c.fill(mark(*p2.at(p2.end()-0.5))) + +c.writeEPSfile("at") +c.writePDFfile("at") diff --git a/examples/path/at.txt b/examples/path/at.txt new file mode 100644 index 00000000..bbae9153 --- /dev/null +++ b/examples/path/at.txt @@ -0,0 +1,33 @@ +Positions at a path + +There are several methods to access certain positions at a path. At first there +are `atbegin` and `atend` methods, which return a coordinate tuple. + +! In this example we have defined a small helper function `mark` to which we +can pass the return value of the `at...` methods. We do this by transforming +the sequence in to positional argument of the function call. This Python +language feature is available by the `*` syntax in the call. + +! The coordinates returned by the `at...` methods are PyX lengths in the +unscaleable true units similar to the return value of the `arclen` method. + +Additionally for the left path `p1` we also show how to use the `at` method, +which can be used to get the coordinates of a certain point of the path +depending on the arc length along the path. + +At the second path `p2` we show a different use of the `at` function: It is +also possible to pass parametrization instances of the path to the `at` method. +In the shown case we first fetch such parametrization instances for the +beginning and the end of the path by the `begin` and `end` methods. Note that +the `atbegin` method is equal to call `at` with the result value of the `begin` +method (except for optimizations: atbegin is faster than the two calls). +Similar `atend` could be rewritten using the result value of `end`. As shown in +the example you can use the parametrization instances to add and substract arc +lengths from selected point. + +!! The `at` method of a path instance can either handle a single value. In that +case it returns a single result tuple. Alternatively you can pass a list to the +method and the return value will contain a list of coordinate tuples. You +should consider to use this later technique, since depending on the use-case it +might be considerably faster compared to multiple calls of the method +performing single conversions each time only. -- 2.11.4.GIT