Circles, Planes, Rays, etc. - s76/libgdx GitHub Wiki

Introduction

Libgdx has several geometric classes for dealing with shapes, areas, and volumes. These include:

A full explanation of these concepts is beyond the current scope, but the above links may provide a starting point for further understanding. What follows is an overview of their use and implementation in Libgdx.


An axis-aligned bounding box useful for simple volume intersection tests. It is defined by a minimum and maximum point describing the rectangular extents of its volume. A point can be tested for containment within the box and the box can be easily resized to contain a given point. Intersection can also be tested against a Frustum (code) or with a Ray (code) using the Intersector (code) class.


A simple class which describes a circle with a center point and a radius. Provides the ability to test a point for containment within the circle. Intersection with another circle, a line segment, or a Rectangle (code) can be tested for using the Intersector (code) class.


A frustum is a four-sided pyramid with the top cut off. It can be used to describe the volume visible to a rectangular view into a space with a perspective projection such as the case with a 3D scene projected onto a 2D monitor.

Frustums can be useful for simplifying a scene by culling objects which do not intersect its volume and are therefore outside of the user's view. Simply pass the combined view-projection matrix of your camera to a frustum instance to create a frustum describing the viewing volume of the screen. Libgdx then provides methods for testing points and simple collision volumes such as bounding boxes (code) and Spheres (code) against the volume of the frustum to determine visibility of scene objects. This is known as "frustum culling," a very common scene optimization technique.


A plane is an infinite two-dimensional surface in three-dimensional space described by a point on that surface and a surface normal. Planes can be useful for partitioning spaces and determining in which sector an object resides. Intersection with a ray (code) or line segment can be tested for using the Intersector (code) class.


A simple class defining a two-dimensional polygon from a list of points. It can be easily translated, rotated, and scaled. It also provides the ability to test a point for containment within the polygon. Polygon to polygon intersection can be tested by using the Intersector (code) class, assuming the polygons are convex.


A ray is a line segment infinite in one direction. It is defined by an origin and a unit-length direction. Rays can be tested for intersection with [bounding boxes] (http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/collision/BoundingBox.html) (code), planes (code), spheres (code), and triangles by using the Intersector (code) class.

Rays are particularly useful in picking operations. Cameras can provide a ray describing the current mouse or touch point in a window projected out into the scene from the point of view of the camera.


A simple class which describes a two-dimensional axis-aligned rectangle described by its bottom-left corner point and a width and height. Provides the ability to test a point for containment within the rectangle. Rectangles can also be tested for intersection with other rectangles as well as with circles (code) by using the Intersector (code) class.


A simple class which describes a line segment in three-dimensional space defined by its two end points. Line segments can be tested for intersection with other line segments, circles (code), and planes(code) by using the Intersector (code) class. This class is merely for convenience in grouping end points as the above tests accept endpoints directly for parameters.


A simple class which describes a three-dimensional sphere defined by a center point and a radius. Can be tested for intersection with Frustum (code) as well as rays (code) by using the Intersector (code) class.

⚠️ **GitHub.com Fallback** ⚠️