Crate cgmath [] [src]

Computer graphics-centric math.

This crate provides useful mathematical primitives and operations on them. It is organized into one module per primitive. The core structures are vectors and matrices. A strongly-typed interface is provided, to prevent mixing units or violating mathematical invariants.

Transformations are not usually done directly on matrices, but go through transformation objects that can be converted to matrices. Rotations go through the Basis types, which are guaranteed to be orthogonal matrices. Despite this, one can directly create a limited rotation matrix using the look_at, from_angle, from_euler, and from_axis_angle methods. These are provided for convenience.

Macros

assert_approx_eq!
assert_approx_eq_eps!

Structs

Aabb2

A two-dimensional AABB, aka a rectangle.

Aabb3

A three-dimensional AABB, aka a rectangular prism.

AffineMatrix3

A homogeneous transformation matrix.

Basis2

A two-dimensional rotation matrix.

Basis3

A three-dimensional rotation matrix.

Cylinder
Decomposed

A generic transformation consisting of a rotation, displacement vector and scale amount.

Deg

An angle, in degrees

Frustum
FrustumPoints
Line

A generic directed line segment from origin to dest.

Matrix2

A 2 x 2, column major matrix

Matrix3

A 3 x 3, column major matrix

Matrix4

A 4 x 4, column major matrix

Obb2
Obb3
Ortho

An orthographic projection with arbitrary left/right/bottom/top distances

Perspective

A perspective projection with arbitrary left/right/bottom/top distances

PerspectiveFov

A perspective projection based on a vertical field-of-view angle.

Plane

A 3-dimensional plane formed from the equation: A*x + B*y + C*z - D = 0.

Point2

A point in 2-dimensional space.

Point3

A point in 3-dimensional space.

Quaternion

A quaternion in scalar/vector form.

Rad

An angle, in radians

Ray

A generic ray starting at origin and extending infinitely in direction.

Sphere
Vector2
Vector3
Vector4

Enums

Relation

Spatial relation between two objects.

Traits

Aabb
Angle

Operations on angles.

ApproxEq
Array1

An array containing elements of type Element

Array2

A column-major array

BaseFloat

Base floating point types

BaseInt

Base integer types

BaseNum

Base numeric types with partial ordering

Bound

Generic bound.

CompositeTransform
CompositeTransform2
CompositeTransform3
EuclideanVector

Specifies geometric operations for vectors. This is only implemented for 2-dimensional and 3-dimensional vectors.

FixedArray

Homogeneous arrays of elements that can be converted to and from [T, ..N] arrays.

Intersect
Matrix
One

Defines a multiplicative identity element for Self.

PartialOrd

A trait providing a partial ordering.

Point

Specifies the numeric operations for point types.

Projection
Rotation

A trait for a generic rotation. A rotation is a transformation that creates a circular motion, and preserves at least one point in the space.

Rotation2

A two-dimensional rotation.

Rotation3

A three-dimensional rotation.

ToComponents

A trait that allows extracting components (rotation, translation, scale) from an arbitrary transformations

ToComponents2
ToComponents3
Transform

A trait representing an affine transformation that can be applied to points or vectors. An affine transformation is one which

Transform2
Transform3
Vector

A trait that specifies a range of numeric operations for vectors. Not all of these make sense from a linear algebra point of view, but are included for pragmatic reasons.

Zero

Defines an additive identity element for Self.

Functions

acos
asin
atan
atan2
bisect
cos
cot
csc
deg

Create a new angle, in degrees

dot

Dot product of two vectors.

frustum

Create a perspective matrix from a view frustrum.

one

Returns the multiplicative identity, 1.

ortho

Create an orthographic projection matrix.

perspective

Create a perspective projection matrix.

rad

Create a new angle, in radians

sec
sin
sin_cos
tan
vec2

The short constructor.

vec3

The short constructor.

vec4

The short constructor.

zero

Returns the additive identity, 0.

Type Definitions

Line2
Line3
Ray2
Ray3