In [12]:
%load_ext autoreload
%autoreload 2
%pylab inline


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Populating the interactive namespace from numpy and matplotlib

In [13]:
from irispy.utils import lcon_to_vert
from irispy.iris import inflate_region

In [14]:
from scipy.spatial import ConvexHull
import numpy as np

In [15]:
obs_1 = np.array([[2,2,3,3],[0,2,2,0]])
obs_2 = np.array([[-1,-1,0,0.2],[0,2,2,0]])
obs_3 = np.array([[0.5,0.5,0.5,0.5],[2,2,2,2]])

In [16]:
obstacle_pts = np.dstack((obs_1, obs_2, obs_3))

In [17]:
A_bounds = np.array([[-1,0],
                     [0,-1],
                     [1,0],
                     [0,1]])
lb = np.array([-1,-1])
ub = np.array([3,3])
b_bounds = np.hstack((-lb, ub))

In [18]:
start = [1,2]

In [19]:
A, b, C, d, results = inflate_region(obstacle_pts, A_bounds, b_bounds, start)

In [20]:
f = figure()
ax = f.add_subplot(111)
hold(True)
for j in range(obstacle_pts.shape[2]):
    obs = obstacle_pts[:,:,j]
    k = range(obs.shape[1]) + [0]
    ax.plot(obs[0,k], obs[1,k], 'k.-')
ax.set_xlim(lb[0]-0.05, ub[0]+0.05)
ax.set_ylim(lb[1]-0.05, ub[1]+0.05)
poly = lcon_to_vert(A, b)
hull = ConvexHull(poly.T)
k = np.hstack((hull.vertices, hull.vertices[0]))
ax.plot(poly[0,k], poly[1,k], 'r.-')
th = np.linspace(0, 2*np.pi, 100)
y = np.vstack((np.cos(th), np.sin(th)))
x = C.dot(y) + d.reshape((-1,1))
ax.plot(x[0,:], x[1,:], 'b-')


Out[20]:
[<matplotlib.lines.Line2D at 0x3aae690>]

In [ ]:


In [ ]: