Class ExtendableConvexPolygonInEnvironment

  • All Implemented Interfaces:
    it.unibo.alchemist.model.geometry.AwtShapeCompatible , it.unibo.alchemist.model.geometry.ConvexPolygon , it.unibo.alchemist.model.geometry.ConvexShape , it.unibo.alchemist.model.geometry.ExtendableConvexPolygon , it.unibo.alchemist.model.geometry.MutableConvexPolygon , it.unibo.alchemist.model.geometry.Shape , java.io.Serializable

    
    public final class ExtendableConvexPolygonInEnvironment
    extends AwtMutableConvexPolygon implements ExtendableConvexPolygon
                        

    An ExtendableConvexPolygon located inside an environment with obstacles. Obstacles, as well as the environment's boundaries, are taken into account when the polygon is extended (i.e. the polygon is prevented from intersecting an obstacle or growing beyond such boundaries). A rectangular region is assumed, its origin, width and height are to be specified. Both java.awt.Shapes and ConvexPolygons can be specified as obstacles (see awtObstacles and polygonalObstacles). This class is explicitly designed for the algorithm contained in generateNavigationGraph. TODO(improve the quality of this class)

    • Method Detail

      • getPolygonalObstacles

         final List<ConvexPolygon> getPolygonalObstacles()

        Obstacles represented as ConvexPolygons, are assumed to be mutable but limited to the extension (i.e. they can only grow, not shrink). This is the behavior of seeds used by generateNavigationGraph, making this assumption allows to cache useful data such as whether an edge can still advance or an obstacle has already been encountered. This is a var but is assumed to be set only once before starting to extend this polygon.

      • setPolygonalObstacles

         final Unit setPolygonalObstacles(List<ConvexPolygon> polygonalObstacles)

        Obstacles represented as ConvexPolygons, are assumed to be mutable but limited to the extension (i.e. they can only grow, not shrink). This is the behavior of seeds used by generateNavigationGraph, making this assumption allows to cache useful data such as whether an edge can still advance or an obstacle has already been encountered. This is a var but is assumed to be set only once before starting to extend this polygon.

      • addVertex

         Boolean addVertex(Integer index, Double x, Double y)

        Adds a vertex to the polygon.

        Parameters:
        index - the index in the list of vertices where to put the new vertex
        x - x coordinate
        y - y coordinate
      • removeVertex

         Boolean removeVertex(Integer index)

        Removes a vertex from the polygon.

        Parameters:
        index - the index of the vertex to be removed in the list of vertices
      • moveVertex

         Boolean moveVertex(Integer index, Double newX, Double newY)

        Moves a vertex of the polygon to a new absolute position.

        Parameters:
        index - the index of the vertex to move
        newX - new absolute x coordinate
        newY - new absolute y coordinate
      • advanceEdge

         Boolean advanceEdge(Integer index, Double step)

        Advances an edge in its normal direction of a quantity equal to step, if extend has modified the growth direction of the edge so as to follow an oblique obstacle (advanced case), the modified growth direction is used. The polygon is prevented from growing out of the environment's boundaries, but not from intersecting obstacles.

        Parameters:
        index - the index of the edge to advance (edge i connects vertices i and i+1)
        step - the length of the vector that will be used to advance the edge, negative values are supported and will shrink the polygon instead of extending it.
      • extend

         Boolean extend(Double step)

        Extends the polygon in each direction of a quantity equal to step. The advancement of an edge is blocked if an obstacle is intersected, unless in a particular case called advanced case. Such case shows up when a single vertex of the polygon intruded an obstacle, but no vertex from the obstacle intruded the polygon. Plus, the intruded side of the obstacle should be oblique (or better, its slope should be different from the one of the advancing edge). When this happens, we can do a simple operation in order to keep growing and allow a higher coverage of the walkable area. We increment the order of the polygon (by adding a vertex) and adjust the direction of growth in order for the new edge to follow the side of the obstacle.

        Parameters:
        step - the length of the vector that will be used to advance each edge, negative values are supported and will shrink the polygon instead of extending it.