X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/2baf863a42cd79849834f7d8ad4d4f428929e3d1..997e3c68590b274c372a6785cda5a69887683891:/doc/examples.rst diff --git a/doc/examples.rst b/doc/examples.rst index 62a7dfd..13c59fc 100644 --- a/doc/examples.rst +++ b/doc/examples.rst @@ -18,16 +18,16 @@ Basic Examples >>> #test equality >>> square1 == square2 False - >>> # find the union of two polygons - >>> square1 + square2 + >>> # compute the union of two polygons + >>> square1 | square2 Or(And(Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)), And(Ge(x - 2, 0), Ge(-x + 4, 0), Ge(y - 2, 0), Ge(-y + 4, 0))) >>> # check if square1 and square2 are disjoint >>> square1.disjoint(square2) False - >>> # find the intersection of two polygons + >>> # compute the intersection of two polygons >>> square1 & square2 And(Eq(y - 2, 0), Eq(x - 2, 0)) - >>> # find the convex union of two polygons + >>> # compute the convex union of two polygons >>> Polyhedron(square1 | sqaure2) And(Ge(x, 0), Ge(-x + 4, 0), Ge(y, 0), Ge(-y + 4, 0), Ge(x - y + 2, 0), Ge(-x + y + 2, 0)) @@ -39,6 +39,7 @@ Basic Examples (x, y) >>> square1.inequalities (x, -x + 2, y, -y + 2) + >>> # project out the variable x >>> square1.project([x]) And(Ge(-y + 2, 0), Ge(y, 0)) @@ -70,4 +71,26 @@ Plot Examples [Point({x: Fraction(0, 1), y: Fraction(1, 1)}), Point({x: Fraction(-1, 1), y: Fraction(0, 1)}), Point({x: Fraction(1, 1), y: Fraction(0, 1)}), Point({x: Fraction(0, 1), y: Fraction(-1, 1)})] >>> diamond.points() [Point({x: -1, y: 0}), Point({x: 0, y: -1}), Point({x: 0, y: 0}), Point({x: 0, y: 1}), Point({x: 1, y: 0})] + + The user also can pass another plot to the :meth:`plot` method. This can be useful to compare two polyhedrons on the same axis. This example illustrates the union of two squares. + + >>> from linpy import * + >>> import matplotlib.pyplot as plt + >>> from matplotlib import pylab + >>> x, y = symbols('x y') + >>> square1 = Le(0, x) & Le(x, 2) & Le(0, y) & Le(y, 2) + >>> square2 = Le(1, x) & Le(x, 3) & Le(1, y) & Le(y, 3) + >>> fig = plt.figure() + >>> plot = fig.add_subplot(1, 1, 1, aspect='equal') + >>> square1.plot(plot, facecolor='red', alpha=0.3) + >>> square2.plot(plot, facecolor='blue', alpha=0.3) + >>> squares = Polyhedron(square1 + square2) + >>> squares.plot(plot, facecolor='blue', alpha=0.3) + >>> pylab.show() + + .. figure:: images/union.jpg + :align: center + + +