APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.math

public Class Polygon

extends Object
implements Shape2D
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.math.Shape2D

Encapsulates a 2D polygon defined by it's vertices relative to an origin point (default of 0, 0).

Field Summary

Modifier and TypeField and Description
private Rectangle
private boolean
private float[]
private float
private float
private float
private float
private float
private float[]
private float
x

private float
y

Constructor Summary

AccessConstructor and Description
public
Polygon()

Constructs a new polygon with no vertices.

public
Polygon(float[]
an array where every even element represents the horizontal part of a point, and the following element representing the vertical part
vertices
)

Constructs a new polygon from a float array of parts of vertex points.

Method Summary

Modifier and TypeMethod and Description
public float
area()

Returns the area contained within the polygon.

public boolean
contains(float x, float y)

Implements com.badlogic.gdx.math.Shape2D.contains.

Returns whether an x, y pair is contained within the polygon.

public boolean
contains(Vector2 point)

Implements com.badlogic.gdx.math.Shape2D.contains.

Returns whether the given point is contained within the shape.

public void
dirty()

Sets the polygon's world vertices to be recalculated when calling getTransformedVertices.

public Rectangle

Returns:

this polygon's bounding box Rectangle
getBoundingRectangle
()

Returns an axis-aligned bounding box of this polygon.

public Vector2
getCentroid(Vector2 centroid)

public float
getOriginX()

Returns the x-coordinate of the polygon's origin point.

public float
getOriginY()

Returns the y-coordinate of the polygon's origin point.

public float
getRotation()

Returns the total rotation applied to the polygon.

public float
getScaleX()

Returns the total horizontal scaling applied to the polygon.

public float
getScaleY()

Returns the total vertical scaling applied to the polygon.

public float[]

Returns:

vertices scaled, rotated, and offset by the polygon position.
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.

public Vector2
getVertex(int vertexNum, Vector2 pos)

Returns: Position(transformed) of vertex

public int
public float[]
getVertices()

Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.

public float
getX()

Returns the x-coordinate of the polygon's position within the world.

public float
getY()

Returns the y-coordinate of the polygon's position within the world.

public void
public void
rotate(float degrees)

Applies additional rotation to the polygon by the supplied degrees.

public void
scale(float amount)

Applies additional scaling to the polygon by the supplied amount.

public void
setOrigin(float originX, float originY)

Sets the origin point to which all of the polygon's local vertices are relative to.

public void
setPosition(float x, float y)

Sets the polygon's position within the world.

public void
setRotation(float degrees)

Sets the polygon to be rotated by the supplied degrees.

public void
setScale(float scaleX, float scaleY)

Sets the amount of scaling to be applied to the polygon.

public void
setVertex(int
min=0, max=vertices.length/2-1
vertexNum
,
float x, float y)

Set vertex position

public void
setVertices(float[]
float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate.
vertices
)

Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.

public void
translate(float x, float y)

Translates the polygon's position by the specified horizontal and vertical amounts.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundsback to summary
private Rectangle bounds
dirtyback to summary
private boolean dirty
localVerticesback to summary
private float[] localVertices
originXback to summary
private float originX
originYback to summary
private float originY
rotationback to summary
private float rotation
scaleXback to summary
private float scaleX
scaleYback to summary
private float scaleY
worldVerticesback to summary
private float[] worldVertices
xback to summary
private float x
yback to summary
private float y

Constructor Detail

Polygonback to summary
public Polygon()

Constructs a new polygon with no vertices.

Polygonback to summary
public Polygon(float[] vertices)

Constructs a new polygon from a float array of parts of vertex points.

Parameters
vertices:float[]

an array where every even element represents the horizontal part of a point, and the following element representing the vertical part

Exceptions
IllegalArgumentException:
if less than 6 elements, representing 3 points, are provided

Method Detail

areaback to summary
public float area()

Returns the area contained within the polygon.

containsback to summary
public boolean contains(float x, float y)

Implements com.badlogic.gdx.math.Shape2D.contains.

Returns whether an x, y pair is contained within the polygon.

Annotations
@Override
containsback to summary
public boolean contains(Vector2 point)

Implements com.badlogic.gdx.math.Shape2D.contains.

Doc from com.badlogic.gdx.math.Shape2D.contains.

Returns whether the given point is contained within the shape.

Annotations
@Override
dirtyback to summary
public void dirty()

Sets the polygon's world vertices to be recalculated when calling getTransformedVertices.

getBoundingRectangleback to summary
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:Rectangle

this polygon's bounding box Rectangle

getCentroidback to summary
public Vector2 getCentroid(Vector2 centroid)
getOriginXback to summary
public float getOriginX()

Returns the x-coordinate of the polygon's origin point.

getOriginYback to summary
public float getOriginY()

Returns the y-coordinate of the polygon's origin point.

getRotationback to summary
public float getRotation()

Returns the total rotation applied to the polygon.

getScaleXback to summary
public float getScaleX()

Returns the total horizontal scaling applied to the polygon.

getScaleYback to summary
public float getScaleY()

Returns the total vertical scaling applied to the polygon.

getTransformedVerticesback to summary
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:float[]

vertices scaled, rotated, and offset by the polygon position.

getVertexback to summary
public Vector2 getVertex(int vertexNum, Vector2 pos)
Returns:Vector2

Position(transformed) of vertex

getVertexCountback to summary
public int getVertexCount()
getVerticesback to summary
public float[] getVertices()

Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.

getXback to summary
public float getX()

Returns the x-coordinate of the polygon's position within the world.

getYback to summary
public float getY()

Returns the y-coordinate of the polygon's position within the world.

resetTransformationsback to summary
public void resetTransformations()
rotateback to summary
public void rotate(float degrees)

Applies additional rotation to the polygon by the supplied degrees.

scaleback to summary
public void scale(float amount)

Applies additional scaling to the polygon by the supplied amount.

setOriginback to summary
public void setOrigin(float originX, float originY)

Sets the origin point to which all of the polygon's local vertices are relative to.

setPositionback to summary
public void setPosition(float x, float y)

Sets the polygon's position within the world.

setRotationback to summary
public void setRotation(float degrees)

Sets the polygon to be rotated by the supplied degrees.

setScaleback to summary
public void setScale(float scaleX, float scaleY)

Sets the amount of scaling to be applied to the polygon.

setVertexback to summary
public void setVertex(int vertexNum, float x, float y)

Set vertex position

Parameters
vertexNum:int

min=0, max=vertices.length/2-1

Exceptions
IllegalArgumentException:
if vertex doesnt exist
setVerticesback to summary
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[]

float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate.

Exceptions
IllegalArgumentException:
if less than 6 elements, representing 3 points, are provided
translateback to summary
public void translate(float x, float y)

Translates the polygon's position by the specified horizontal and vertical amounts.