def draw_graph(self, rnd=None): plt.clf() if rnd is not None: plt.plot(rnd.x, rnd.y, "^k") for node in self.node_list: if node.parent: plt.plot(node.path_x, node.path_y, "-g") for (A, b) in self.obstacle_list: vtc = ppm.compute_polytope_vertices(A, b) ppm.plot_polygon(vtc, color='r') ''' plt.plot(ox, oy, "ok", ms=30 * size) ''' ppm.plot_polygon(self.start_vtc, color='b') ppm.plot_polygon(self.end_vtc, color='g') # plt.axis([-2, 15, -2, 15]) plt.grid(True) plt.pause(0.01)
def show_rmp(self): if len(self.limits) != 2: raise Exception("Plot currently supported only for 2D") vtcs = [[*vtx.position] for vtx in self.vertices.values()] print(vtcs) pypoman.plot_polygon(vtcs)
# version. # # pypoman is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # pypoman. If not, see <http://www.gnu.org/licenses/>. import pylab from numpy import arange, array, cos, pi, sin import pypoman vertices = [(cos(theta), sin(theta)) for theta in arange(0, 2 * pi, pi / 6)] A, b = pypoman.compute_polytope_halfspaces(vertices) point = array([2.1, 1.9]) proj = pypoman.project_point_to_polytope(point, (A, b)) if __name__ == "__main__": # plot projected polytope pylab.ion() pylab.figure() pylab.gca().set_aspect("equal") pypoman.plot_polygon(vertices) pylab.plot([point[0]], [point[1]], marker='o', markersize=3, color='r') pylab.plot([proj[0]], [proj[1]], marker='o', markersize=3, color='b') pylab.plot([point[0], proj[0]], [point[1], proj[1]], 'b--') pylab.show(block=True)
import pypoman n = 10 # dimension of the original polytope p = 2 # dimension of the projected polytope # Original polytope: # - inequality constraints: \forall i, |x_i| <= 1 # - equality constraint: sum_i x_i = 0 A = vstack([+eye(n), -eye(n)]) b = ones(2 * n) C = ones(n).reshape((1, n)) d = array([0]) ineq = (A, b) # A * x <= b eq = (C, d) # C * x == d # Projection is proj(x) = [x_0 x_1] E = zeros((p, n)) E[0, 0] = 1. E[1, 1] = 1. f = zeros(p) proj = (E, f) # proj(x) = E * x + f vertices = pypoman.project_polytope(proj, ineq, eq, method='bretl') if __name__ == "__main__": # plot projected polytope pylab.ion() pylab.figure() pypoman.plot_polygon(vertices, resize=True) pylab.show(block=True)