Package com.badlogic.gdx.math
Class Polygon
- java.lang.Object
-
- com.badlogic.gdx.math.Polygon
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatarea()Returns the area contained within the polygon.booleancontains(float x, float y)Returns whether an x, y pair is contained within the polygon.booleancontains(Vector2 point)Returns whether the given point is contained within the shape.voiddirty()Sets the polygon's world vertices to be recalculated when callinggetTransformedVertices.RectanglegetBoundingRectangle()Returns an axis-aligned bounding box of this polygon.Vector2getCentroid(Vector2 centroid)floatgetOriginX()Returns the x-coordinate of the polygon's origin point.floatgetOriginY()Returns the y-coordinate of the polygon's origin point.floatgetRotation()Returns the total rotation applied to the polygon.floatgetScaleX()Returns the total horizontal scaling applied to the polygon.floatgetScaleY()Returns the total vertical scaling applied to the polygon.float[]getTransformedVertices()Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied, as they are position within the world.Vector2getVertex(int vertexNum, Vector2 pos)intgetVertexCount()float[]getVertices()Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.floatgetX()Returns the x-coordinate of the polygon's position within the world.floatgetY()Returns the y-coordinate of the polygon's position within the world.voidrotate(float degrees)Applies additional rotation to the polygon by the supplied degrees.voidscale(float amount)Applies additional scaling to the polygon by the supplied amount.voidsetOrigin(float originX, float originY)Sets the origin point to which all of the polygon's local vertices are relative to.voidsetPosition(float x, float y)Sets the polygon's position within the world.voidsetRotation(float degrees)Sets the polygon to be rotated by the supplied degrees.voidsetScale(float scaleX, float scaleY)Sets the amount of scaling to be applied to the polygon.voidsetVertex(int vertexNum, float x, float y)Set vertex positionvoidsetVertices(float[] vertices)Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.voidtranslate(float x, float y)Translates the polygon's position by the specified horizontal and vertical amounts.
-
-
-
Constructor Detail
-
Polygon
public Polygon()
Constructs a new polygon with no vertices.
-
Polygon
public Polygon(float[] vertices)
Constructs a new polygon from a float array of parts of vertex points.- Parameters:
vertices- an array where every even element represents the horizontal part of a point, and the following element representing the vertical part- Throws:
java.lang.IllegalArgumentException- if less than 6 elements, representing 3 points, are provided
-
-
Method Detail
-
getVertices
public float[] getVertices()
Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.
-
getTransformedVertices
public float[] getTransformedVertices()
Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied, as they are position within the world.- Returns:
- vertices scaled, rotated, and offset by the polygon position.
-
setOrigin
public void setOrigin(float originX, float originY)Sets the origin point to which all of the polygon's local vertices are relative to.
-
setPosition
public void setPosition(float x, float y)Sets the polygon's position within the world.
-
setVertices
public void setVertices(float[] vertices)
Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.- Parameters:
vertices- float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate.- Throws:
java.lang.IllegalArgumentException- if less than 6 elements, representing 3 points, are provided
-
setVertex
public void setVertex(int vertexNum, float x, float y)Set vertex position- Parameters:
vertexNum- min=0, max=vertices.length/2-1- Throws:
java.lang.IllegalArgumentException- if vertex doesnt exist
-
translate
public void translate(float x, float y)Translates the polygon's position by the specified horizontal and vertical amounts.
-
setRotation
public void setRotation(float degrees)
Sets the polygon to be rotated by the supplied degrees.
-
rotate
public void rotate(float degrees)
Applies additional rotation to the polygon by the supplied degrees.
-
setScale
public void setScale(float scaleX, float scaleY)Sets the amount of scaling to be applied to the polygon.
-
scale
public void scale(float amount)
Applies additional scaling to the polygon by the supplied amount.
-
dirty
public void dirty()
Sets the polygon's world vertices to be recalculated when callinggetTransformedVertices.
-
area
public float area()
Returns the area contained within the polygon.
-
getVertexCount
public int getVertexCount()
-
getVertex
public Vector2 getVertex(int vertexNum, Vector2 pos)
- Returns:
- Position(transformed) of vertex
-
getBoundingRectangle
public Rectangle getBoundingRectangle()
Returns an axis-aligned bounding box of this polygon. Note the returned Rectangle is cached in this polygon, and will be reused if this Polygon is changed.- Returns:
- this polygon's bounding box
Rectangle
-
contains
public boolean contains(float x, float y)Returns whether an x, y pair is contained within the polygon.
-
contains
public boolean contains(Vector2 point)
Description copied from interface:Shape2DReturns whether the given point is contained within the shape.
-
getX
public float getX()
Returns the x-coordinate of the polygon's position within the world.
-
getY
public float getY()
Returns the y-coordinate of the polygon's position within the world.
-
getOriginX
public float getOriginX()
Returns the x-coordinate of the polygon's origin point.
-
getOriginY
public float getOriginY()
Returns the y-coordinate of the polygon's origin point.
-
getRotation
public float getRotation()
Returns the total rotation applied to the polygon.
-
getScaleX
public float getScaleX()
Returns the total horizontal scaling applied to the polygon.
-
getScaleY
public float getScaleY()
Returns the total vertical scaling applied to the polygon.
-
-