PyX — Example: path/

0.4 KB
3.8 KB
0.8 KB
1.4 KB

Intersection points between paths

from pyx import *

p1 = path.curve(0, 0, 1, 0, 1, 1, 2, 1)
p2 =, 0.5, 0.5)

(a1, a2), (b1, b2) = p1.intersect(p2)

x1, y1 =
x2, y2 =

c = canvas.canvas()
c.fill(, y1, 0.1), [])
c.fill(, y2, 0.1), [])
c.stroke(p1, [])
c.stroke(p2, [])


The intersect method of a path allows for the calculation of intersection points between this path and the second path passed to the intersect method. The return value of the intersect method is a tuple of two lists, where each list contains parametrization instances for the intersection points. The first list are the parameters for the path the intersect method was called for. The second list are the parameter values for the path passed to the intersect method. Thus we can calculate the first intersection point x1, y1 by

x1, y1 =

as done in the example or alternatively by

x1, y1 =

When several intersections between two paths occur, the order of the intersection points is defined by the order in which the points are passed when walking along the first path.