Skip to content

Invalid region returned when there are obstacles that exceed the bounds. #68

@enriquefernandez

Description

@enriquefernandez

Hello,

I'm not sure if this is a bug, or if obstacles are not allowed to exceed the bounds and this is expected behavior.

Basically, IRIS is returning a degenerate region that is invalid when there are obstacles that intersect the environment bounds.

The left figure shows, in green, the region that IRIS returns when using the obstacles in blue, the seed point as the red cross and when the boundary is the large box with black edges.

On the right, the same result when the boundary used is the yellow area instead. As you can see the region returned consists of three vertices where two of them are the same point. Moreover, one of those vertices is outside the boundary.

Just leaving this here in case this is something that should be fixed.
By the way, thanks for making this available, Robin. It works fantastically well and it's really easy to use!

iris_issue

The vertices of the regions are:

IRIS region when using big bounds:
 [[  3.86205232   2.89598565]
 [  4.12493869   5.        ]
 [ 15.           1.83012696]
 [ 15.           5.        ]]
IRIS region when using small bounds:
 [[  3.75000000e+00   2.00000000e+00]
 [  3.75000000e+00   2.00002585e+00]
 [  4.20400665e-12   5.03153075e-13]]

The code I used to generate this problem is the following (Jupyter notebook):

%matplotlib inline
import irispy
import matplotlib.pyplot as plt
import numpy as np
import scipy

def plot_polygon(vertices, ax=None, draw_vertices=False, **kwargs):
        if ax is None:
            ax = plt.gca()
        hull = scipy.spatial.ConvexHull(vertices)
        kwargs.setdefault("facecolor", "none")
        
        if draw_vertices:
            xx, yy = list(zip(*vertices))
            plt.plot(xx, yy, 'o',color='red')
        
        return [ax.add_patch(plt.Polygon(xy=vertices[hull.vertices],**kwargs))]
def plot_bounds(bounds, ax=None, **kwargs):
    (minx, miny), (maxx, maxy) = bounds
    vertices = np.array([[minx,miny], [minx,maxy], [maxx, maxy], [maxx, miny]])
    plot_polygon(vertices, ax, **kwargs)

def plot_scenario():
    # Plot big boundary
    plt.figure(figsize=(14,7))
    for i in range(2):
        plt.subplot(1,2,i+1)
        plot_bounds(big_bounds, alpha=0.3, facecolor='none', edgecolor='black')

        plt.xlim([minx-1, maxx+1])
        plt.ylim([miny-1, maxy+1])

        for obs in obstacles:
            vertices = np.array(list(zip(*obs)))
            plot_polygon(vertices,facecolor='blue', alpha=0.5)

        # Plot seed
        plt.plot(seed[0], seed[1], 'xr')
    
    
# Case with no errors
big_bounds = (-5, -4), (15, 5)
small_bounds = (3.75, 2.0), (8, 3.88)
(minx, miny), (maxx, maxy) = big_bounds
obstacles = [np.array([[  3. ,  10. ,  10. ,   3. ,   3. ],
        [  1.5,   1.5,   2. ,   2. ,   1.5]]),
         np.array([[ 2.,  3.,  4.,  3.,  2.],
        [-4.,  4.,  4., -4., -4.]]),
         np.array([[ 7. ,  7.5,  8. ,  7.5,  7. ],
        [-2. , -2. ,  2.5,  2.5, -2. ]])]
seed = np.array([ 6.25318857,  2.48619646])

plot_scenario()

plt.subplot(1,2,1)
# with big bounds
iris_bounds = irispy.Polyhedron.fromBounds(*big_bounds)
ir = irispy.inflate_region(obstacles, seed, iris_bounds)    
reg_vertices1 = ir.getPolyhedron().getDrawingVertices()
plot_polygon(reg_vertices1, draw_vertices=True, facecolor='green', alpha=0.2)


plt.subplot(1,2,2)
# with small bounds
plot_bounds(small_bounds, alpha=0.3, facecolor='yellow', edgecolor='black')
iris_bounds = irispy.Polyhedron.fromBounds(*small_bounds)
ir = irispy.inflate_region(obstacles, seed, iris_bounds)    
reg_vertices2 = ir.getPolyhedron().getDrawingVertices()
plot_polygon(reg_vertices2, draw_vertices=True, facecolor='green', alpha=0.2)

print("IRIS region when using big bounds:\n", reg_vertices1)
print("IRIS region when using small bounds:\n", reg_vertices2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions