Hello Alan,

On 18.07.08, Alan G Isaac wrote:
> The example at 
> http://pyx.sourceforge.net/gallery/graphs/integral.html

> I get the basic idea, but I'd like more than a basic
> understanding.

I do not know which level of understanding you want to reach -- I just
start here with some explanation, you can then ask in more detail.

>     p = d.path # the path is available after the graph is finished

The g.plot command returned the "plot-object" d which contains some
information on the plotted data, such as the title and the path which
is plotted. We here want the path and call it p. p consists of 100
short lines which are concatenated to give some curved impression.
Note that the path is just a path instance, completely independent of
the graph. This allows to stroke the same path on a completely
different canvas. (the easiest way to strip all axes off a graph)

>     pa = g.xgridpath(a)
>     pb = g.xgridpath(b)

We want the points where two vertical lines intersect with the path p.
We here ask the graph to give us these lines. When calling xgridpath,
the graph asks its "x" axis to find the position of the values a and b
and returns a path parallel to the y axis. Alternatively, we could
have asked for the position of the values a and b and created the path
ourselves, such as

    x = g.pos(a, 0.0)[0]
    pa = path.line(0, x, 10, x)

but this requires that we know something about the y-range (0.0 has to
be a reasonable value) and something about the position and size of
the graph (0 should be below the x-axis, and 10 above the graph of the
function). the xgridpath does all that automatically

>     (splita,), (splitpa,) = p.intersect(pa)
>     (splitb,), (splitpb,) = p.intersect(pb)

These two commands do the intersections of the "curved" path p with
the vertical lines. The result of each intersection is a pair of
parameters which tell us where to find the common point on each of the
paths. As we use p.intersect(pa) the first parameter is the one for p
and the second for pa. We could equally write

      (splitpa,), (splita,) = pa.intersect(p)

The notation with the tuples is a bit peculiar, but necessary: In
principle, one does not know in advance how many intersection points
will be found. Therefore, we always obtain a list of parameters for
each path. In this very example, we expect only one common point and
give names to the two parameters received. The above command would
fail if there were more than one intersection points.

>     area = (pa.split([splitpa])[0] <<
>             p.split([splita, splitb])[1] <<
>             pb.split([splitpb])[0].reversed())

Next, we take the required pieces of the three paths p, pa, pb and
glue them together. The split methods gives us pieces of the paths,
split at given parameters. Again, this is possible for several
parameters, therefore we always have to provide a list of parameters
and receive a list of pieces of the original path. We have to choose
the correct piece (by saying [0] or [1]). The operator << glues the
pieces together. This operator throws away possible path.moveto at the
beginning of the pieces -- this is different for the adding of paths
by the "+" operator, which keeps the moveto. Actually, "area" is an
open path at the moment. If we want to fill it, we must rely on the
convention that postscript/pdf fills the region within an open path.
We could add a path.closepath() explicitly. For filling, the direction
of the surrounding path pieces is important. We go up along the path
pa, then right along p. To go down on the path pb we must reverse its
original direction. (It is here important to know the original
directions of the xgridpaths and of the path of the plotobject).

Michael



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to