Documentation of 'math.geom2d.polygon.SimplePolygon2D' Java class
SimplePolygon2D
math.geom2d.polygon

Class SimplePolygon2D

    • Constructor Detail

      • SimplePolygon2D

        public SimplePolygon2D()
        Empty constructor: no vertex.
      • SimplePolygon2D

        public SimplePolygon2D(Point2D... vertices)
        Constructor from an array of points
        Parameters:
        vertices - the vertices stored in an array of Point2D
      • SimplePolygon2D

        public SimplePolygon2D(double[] xcoords,
                               double[] ycoords)
        Constructor from two arrays, one for each coordinate.
        Parameters:
        xcoords - the x coordinate of each vertex
        ycoords - the y coordinate of each vertex
      • SimplePolygon2D

        public SimplePolygon2D(java.util.Collection<? extends Point2D> points)
      • SimplePolygon2D

        public SimplePolygon2D(int nVertices)
        Ensure the polygon has enough memory for storing the required number of vertices.
      • SimplePolygon2D

        public SimplePolygon2D(LinearRing2D ring)
        Creates a simple polygon with the given linear ring representing its boundary.
        Parameters:
        ring - the boundary of the polygon
    • Method Detail

      • create

        public static SimplePolygon2D create(java.util.Collection<? extends Point2D> points)
        Static factory for creating a new SimplePolygon2D from a collection of points.
        Since:
        0.8.1
      • create

        public static SimplePolygon2D create(Point2D... points)
        Static factory for creating a new SimplePolygon2D from an array of points.
        Since:
        0.8.1
      • getWindingNumber

        public int getWindingNumber(double x,
                                    double y)
        Computes the winding number of the polygon. Algorithm adapted from http://www.geometryalgorithms.com/Archive/algorithm_0103/algorithm_0103.htm
        Parameters:
        x - the x-coordinate of the point
        y - the y-coordinate of the point
        Returns:
        the number of windings of the curve around the point
      • simplify

        public SimplePolygon2D simplify(double distMax)
        Returns a simplified version of this polygon, by using Douglas-Peucker algorithm.
      • getRing

        public LinearRing2D getRing()
        Returns the linear ring that composes the boundary of this polygon.
        Since:
        0.9.3
      • addVertex

        public void addVertex(Point2D point)
        Adds a point as the last vertex.
        Specified by:
        addVertex in interface Polygon2D
        Parameters:
        point - the position of the new vertex
      • insertVertex

        public void insertVertex(int index,
                                 Point2D point)
        Adds a point as the last vertex.
        Specified by:
        insertVertex in interface Polygon2D
        Parameters:
        index - index at which the specified vertex is to be inserted
        point - the position of the new vertex
        Since:
        0.9.3
      • setVertex

        public void setVertex(int index,
                              Point2D position)
        Changes the position of the i-th vertex.
        Specified by:
        setVertex in interface Polygon2D
        Parameters:
        index - the vertex index
        position - the new position of the vertex
      • removeVertex

        public boolean removeVertex(Point2D point)
        Removes a vertex of the polygon.
        Parameters:
        point - the vertex to be removed.
      • removeVertex

        public void removeVertex(int index)
        Removes a vertex of the polygon specified by its index.
        Specified by:
        removeVertex in interface Polygon2D
        Parameters:
        index - index of the vertex to remove
        Since:
        0.9.3
      • clearVertices

        public void clearVertices()
        Removes all the vertices of the polygon.
      • closestVertexIndex

        public int closestVertexIndex(Point2D point)
        Computes the index of the closest vertex to the input point.
        Specified by:
        closestVertexIndex in interface Polygon2D
      • area

        public double area()
        Computes the signed area of the polygon. Algorithm is taken from page: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/. Signed are is positive if polygon is oriented counter-clockwise, and negative otherwise. Result is wrong if polygon is self-intersecting.
        Specified by:
        area in interface Polygon2D
        Returns:
        the signed area of the polygon.
      • vertices

        public java.util.Collection<Point2D> vertices()
        Returns the points of the polygon. The result is a pointer to the inner collection of vertices.
        Specified by:
        vertices in interface Polygon2D
      • vertex

        public Point2D vertex(int i)
        Returns the i-th vertex of the polygon.
        Specified by:
        vertex in interface Polygon2D
        Parameters:
        i - index of the vertex, between 0 and the number of vertices
      • vertexNumber

        public int vertexNumber()
        Returns the number of vertices of the polygon.
        Specified by:
        vertexNumber in interface Polygon2D
        Since:
        0.6.3
      • edges

        public java.util.Collection<LineSegment2D> edges()
        Returns the set of edges, as a collection of LineSegment2D.
        Specified by:
        edges in interface Polygon2D
      • edgeNumber

        public int edgeNumber()
        Returns the number of edges. For a simple polygon, this equals the number of vertices.
        Specified by:
        edgeNumber in interface Polygon2D
      • buffer

        public CirculinearDomain2D buffer(double dist)
        Description copied from interface: CirculinearShape2D
        Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.
        Specified by:
        buffer in interface CirculinearShape2D
        Parameters:
        dist - the maximal distance between a point of the buffer and the shape
        Returns:
        the buffer of the shape
      • asPolygon

        public Polygon2D asPolygon(int n)
        Description copied from interface: Domain2D
        Returns an approximation of the domain as a polygon, or a MultiPolygon.
        Specified by:
        asPolygon in interface Domain2D
        Returns:
        a polygon
      • distance

        public double distance(Point2D p)
        Returns the distance of the point to the polygon. The result is the minimal distance computed for each edge if the polygon, or ZERO if the point lies inside the polygon.
        Specified by:
        distance in interface Shape2D
      • distance

        public double distance(double x,
                               double y)
        Returns the distance of the point to the polygon. The result is the minimal distance computed for each edge if the polygon, or ZERO if the point lies inside the polygon.
        Specified by:
        distance in interface Shape2D
      • clip

        public Polygon2D clip(Box2D box)
        Returns the shape formed by the polygon clipped by the given box.
        Specified by:
        clip in interface Domain2D
        Specified by:
        clip in interface Polygon2D
        Specified by:
        clip in interface Shape2D
        Parameters:
        box - the clipping box
        Returns:
        the clipped shape
      • boundingBox

        public Box2D boundingBox()
        Returns the bounding box of the polygon.
        Specified by:
        boundingBox in interface Shape2D
        Returns:
        the bounding box of the shape.
      • isBounded

        public boolean isBounded()
        Returns true if polygon is oriented counter-clockwise, false otherwise.
        Specified by:
        isBounded in interface Shape2D
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Shape2D
        Returns true if the shape does not contain any point. This is the case for example for PointSet2D without any point.
        Specified by:
        isEmpty in interface Shape2D
        Returns:
        true if the shape does not contain any point.
      • transform

        public SimplePolygon2D transform(AffineTransform2D trans)
        Returns the new Polygon created by an affine transform of this polygon. If the transform is not direct, the order of vertices is reversed.
        Specified by:
        transform in interface Domain2D
        Specified by:
        transform in interface Polygon2D
        Specified by:
        transform in interface Shape2D
        Parameters:
        trans - an affine transform
        Returns:
        the transformed shape
      • contains

        public boolean contains(Point2D p)
        Returns true if the point p lies inside the polygon, with precision given by Shape2D.ACCURACY.
        Specified by:
        contains in interface Shape2D
      • contains

        public boolean contains(double x,
                                double y)
        Returns true if the point (x, y) lies inside the polygon, with precision given by Shape2D.ACCURACY.
        Specified by:
        contains in interface Shape2D
      • getGeneralPath

        public java.awt.geom.GeneralPath getGeneralPath()
        Returns a general path iterator.
      • draw

        public void draw(java.awt.Graphics2D g2)
        Description copied from interface: Shape2D
        Draws the shape on the given graphics. If the shape is empty, nothing is drawn. If the shape is unbounded, an exception is thrown.
        Specified by:
        draw in interface Domain2D
        Specified by:
        draw in interface Shape2D
        Parameters:
        g2 - the Graphics to draw on
      • fill

        public void fill(java.awt.Graphics2D g)
        Description copied from interface: Domain2D
        Fills the interior of the domain, using the Graphics current Paint.
        Specified by:
        fill in interface Domain2D
        Parameters:
        g - the Graphics to fill on
      • almostEquals

        public boolean almostEquals(GeometricObject2D obj,
                                    double eps)
        Description copied from interface: GeometricObject2D
        Checks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.
        Specified by:
        almostEquals in interface GeometricObject2D
        Parameters:
        obj - the object to compare
        eps - a threshold value, for example the minimal coordinate difference
        Returns:
        true if both object have the same value up to the threshold
      • equals

        public boolean equals(java.lang.Object obj)
        Tests if the two polygons are equal. Test first the number of vertices, then the bounding boxes, then if each vertex of the polygon is contained in the vertices array of this polygon.
        Overrides:
        equals in class java.lang.Object
      • clone

        @Deprecated
        public SimplePolygon2D clone()
        Deprecated. use copy constructor instead (0.11.2)
        Overrides:
        clone in class java.lang.Object

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.