User Tools

Site Tools


3d_geometric_shapes

This is an old revision of the document!


3D Geometry in Impulse Physics

Currently, there is support for the following primitives:

  • AABB
  • Line
  • OrientedBox
  • Plane
  • Rays (for use in Raycasting)
  • Sphere
  • Triangle

AABB

An Axis-Aligned Bounding Box, or 'AABB', is as the name implies a box that is aligned with the coordinate system's axes. It is a rectangular box that completely encloses an object or set of objects by defining the minimum and maximum points in each of the three dimensions. The edges of the box are parallel to the x, y, and z axes, which simplifies collision detection and spatial calculations.

The AABB (Axis-Aligned Bounding Box) struct represents a rectangular cuboid in 3D space that is aligned with the X, Y, and Z axes.

It has three fields:

  1. origin: a Point (x,y,z) representing the center of the cuboid
  2. size: a Vector3 (x,y,z) representing the length, width, and height of the cuboid

It also has three constructors:

  1. AABB(): sets the origin to (0,0,0) and size to (1,1,1)
  2. AABB(const Point& o, const Vector3& s): sets the origin to the given point and size to the given vector
  3. AABB(const Vector3& min, const Vector3& max, bool isHalved = true): creates an AABB from two opposing corner points, min and max. If isHalved is true (default), the origin is set to the center of the cuboid and the size is half the distance between the min and max points. If isHalved is false, the origin is set to the average of the min and max points and the size is the full distance between them.

The struct also provides two methods for getting the minimum and maximum points of the AABB:

  1. GetMin(): returns a Vector3 representing the minimum x, y, and z values of the AABB
  2. GetMax(): returns a Vector3 representing the maximum x, y, and z values of the AABB

Example usage:

AABB box1; // creates an AABB centered at (0,0,0) with size (1,1,1)
AABB box2(Point(1,2,3), Vector3(2,3,4)); // creates an AABB centered at (1,2,3) with size (2,3,4)
AABB box3(Vector3(-1,-1,-1), Vector3(1,1,1)); // creates an AABB centered at (0,0,0) with size (2,2,2)

Line

The Line struct represents a line in 3D space with a start and end point.

It has two fields:

  1. start: a Point (x,y,z) representing the starting point of the line
  2. end: a Point (x,y,z) representing the ending point of the line

It also has two constructors:

  1. Line(): sets both start and end points to (0,0,0)
  2. Line(const Point& s, const Point& e): sets the start point to the given point s and the end point to the given point e

The struct provides two static methods for getting the length of a line:

  1. Length(const Line& line): returns the length of the given line using the Magnitude() method of the vector between its start and end points
  2. LengthFast(const Line& line): returns an approximation of the length of the given line using the MagnitudeFast() method of the vector between its start and end points, which trades accuracy for speed.

Example usage:

Line line1; // creates a line with start and end points at (0,0,0)
Line line2(Point(1,2,3), Point(4,5,6)); // creates a line with start at (1,2,3) and end at (4,5,6)
float length = Line::Length(line2); // computes the length of line2 using the precise Magnitude() method
float lengthFast = Line::LengthFast(line2); // computes an approximation of the length of line2 using the faster MagnitudeFast() method

Oriented Box

The OrientedBox struct represents a box-shaped object in 3D space, oriented in any direction.

It has three fields:

  1. position: a Point (x,y,z) representing the position of the center of the box in 3D space
  2. size: a Vector3 (x,y,z) representing the dimensions of the box (length, width, height)
  3. orientation: a Matrix3x3 representing the rotation of the box in 3D space

It has three constructors:

  1. OrientedBox(): sets position to (0,0,0), size to (1,1,1), and orientation to the identity matrix (no rotation)
  2. OrientedBox(const Point& p, const Vector3& s): sets the position to the given point p, the size to the given vector s, and orientation to the identity matrix (no rotation)
  3. OrientedBox(const Point& p, const Vector3& s, const Matrix3x3& o): sets the position to the given point p, the size to the given vector s, and orientation to the given matrix o (for arbitrary rotation)

Example usage:

OrientedBox box1; // creates a unit box centered at (0,0,0) with no rotation
OrientedBox box2(Point(1,2,3), Vector3(2,3,4)); // creates a box with center at (1,2,3), size (2,3,4), and no rotation
Matrix3x3 rotation = // some arbitrary 3x3 rotation matrix
OrientedBox box3(Point(0,0,0), Vector3(1,1,1), rotation); // creates a unit box at the origin, with rotation specified by the given matrix
3d_geometric_shapes.1681415553.txt.gz · Last modified: 2023/04/13 19:52 by max