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)
-
-
Field Summary
Fields Modifier and Type Field Description private List<ConvexPolygon>
polygonalObstacles
private final Double
diameter
private final Euclidean2DPosition
centroid
private final Double
radius
-
Constructor Summary
Constructors Constructor Description ExtendableConvexPolygonInEnvironment(List<Euclidean2DPosition> vertices, Euclidean2DPosition origin, Double width, Double height, List<Shape> awtObstacles)
-
Method Summary
Modifier and Type Method Description final List<ConvexPolygon>
getPolygonalObstacles()
Obstacles represented as ConvexPolygons, are assumed to be mutable but limited to the extension (i.e. final Unit
setPolygonalObstacles(List<ConvexPolygon> polygonalObstacles)
Obstacles represented as ConvexPolygons, are assumed to be mutable but limited to the extension (i.e. Boolean
addVertex(Integer index, Double x, Double y)
Adds a vertex to the polygon. Boolean
removeVertex(Integer index)
Removes a vertex from the polygon. Boolean
moveVertex(Integer index, Double newX, Double newY)
Moves a vertex of the polygon to a new absolute position. Boolean
replaceEdge(Integer index, Segment2D<Euclidean2DPosition> newEdge)
Replaces an edge of the polygon. 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. Boolean
extend(Double step)
Extends the polygon in each direction of a quantity equal to step. Boolean
equals(Object other)
Integer
hashCode()
-
Methods inherited from class it.unibo.alchemist.model.geometry.AwtMutableConvexPolygon
asAwtShape, contains, edges, getCentroid, getDiameter, getEdge, intersects, intersects, transformed, vertices
-
Methods inherited from class it.unibo.alchemist.model.geometry.Shape
getRadius
-
Methods inherited from class it.unibo.alchemist.model.geometry.AbstractConvexPolygon
closestEdgeTo, contains, containsBoundaryExcluded, containsBoundaryIncluded, intersects, isAdjacentTo, liesOnBoundary, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ExtendableConvexPolygonInEnvironment
ExtendableConvexPolygonInEnvironment(List<Euclidean2DPosition> vertices, Euclidean2DPosition origin, Double width, Double height, List<Shape> awtObstacles)
-
-
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 vertexx
- x coordinatey
- 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 movenewX
- new absolute x coordinatenewY
- new absolute y coordinate
-
replaceEdge
Boolean replaceEdge(Integer index, Segment2D<Euclidean2DPosition> newEdge)
Replaces an edge of the polygon.
- Parameters:
index
- the index of the edge to replace (edge i connects vertices i and i+1)newEdge
- the new edge
-
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.
-
-
-
-