The Basis built-in Variant type is a 3×3 matrix used to represent 3D rotation, scale, and shear. It is frequently used within a Transform3D.
A Basis is composed by 3 axis vectors, each representing a column of the matrix: x, y, and z. The length of each axis (Vector3.length()) influences the basis's scale, while the direction of all axes influence the rotation. Usually, these axes are perpendicular to one another. However, when you rotate any axis individually, the basis becomes sheared. Applying a sheared basis to a 3D model will make the model appear distorted.
A Basis is:
Orthogonal if its axes are perpendicular to each other.
Normalized if the length of every axis is 1.0
.
Uniform if all axes share the same length (see get_scale()).
Orthonormal if it is both orthogonal and normalized, which allows it to only represent rotations (see orthonormalized()).
Conformal if it is both orthogonal and uniform, which ensures it is not distorted.
For a general introduction, see the Matrices and transforms tutorial.
Constructs a Basis identical to IDENTITY.
Note: In C#, this constructs a Basis with all of its components set to Vector3.ZERO.
Constructs a Basis as a copy of the given Basis.
Constructs a Basis that only represents rotation, rotated around the axis
by the given angle
, in radians. The axis must be a normalized vector.
Note: This is the same as using rotated() on the IDENTITY basis. With more than one angle consider using from_euler(), instead.
Constructs a Basis that only represents rotation from the given Quaternion.
Note: Quaternions only store rotation, not scale. Because of this, conversions from Basis to Quaternion cannot always be reversed.
Constructs a Basis from 3 axis vectors. These are the columns of the basis matrix.
Returns true
if the components of both Basis matrices are not equal.
Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.
Transforms (multiplies) the right
basis by this basis.
This is the operation performed between parent and child Node3Ds.
Transforms (multiplies) the right
vector by this basis, returning a Vector3.
Multiplies all components of the Basis by the given float. This affects the basis's scale uniformly, resizing all 3 axes by the right
value.
Multiplies all components of the Basis by the given int. This affects the basis's scale uniformly, resizing all 3 axes by the right
value.
Divides all components of the Basis by the given float. This affects the basis's scale uniformly, resizing all 3 axes by the right
value.
Divides all components of the Basis by the given int. This affects the basis's scale uniformly, resizing all 3 axes by the right
value.
Returns true
if the components of both Basis matrices are exactly equal.
Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.
Accesses each axis (column) of this basis by their index. Index 0
is the same as x, index 1
is the same as y, and index 2
is the same as z.
Note: In C++, this operator accesses the rows of the basis matrix, not the columns. For the same behavior as scripting languages, use the set_column
and get_column
methods.
The basis's X axis, and the column 0
of the matrix.
On the identity basis, this vector points right (Vector3.RIGHT).
The basis's Y axis, and the column 1
of the matrix.
On the identity basis, this vector points up (Vector3.UP).
The basis's Z axis, and the column 2
of the matrix.
On the identity basis, this vector points back (Vector3.BACK).
Returns the determinant of this basis's matrix. For advanced math, this number can be used to determine a few attributes:
If the determinant is exactly 0.0
, the basis is not invertible (see inverse()).
If the determinant is a negative number, the basis represents a negative scale.
Note: If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2.
Constructs a new Basis that only represents rotation from the given Vector3 of Euler angles, in radians.
The Vector3.x should contain the angle around the x axis (pitch);
The Vector3.y should contain the angle around the y axis (yaw);
The Vector3.z should contain the angle around the z axis (roll).
The order of each consecutive rotation can be changed with order
(see EulerOrder constants). By default, the YXZ convention is used (@GlobalScope.EULER_ORDER_YXZ): the basis rotates first around the Y axis (yaw), then X (pitch), and lastly Z (roll). When using the opposite method get_euler(), this order is reversed.
Constructs a new Basis that only represents scale, with no rotation or shear, from the given scale
vector.
Note: In linear algebra, the matrix of this basis is also known as a diagonal matrix.
Returns this basis's rotation as a Vector3 of Euler angles, in radians. For the returned value:
The order of each consecutive rotation can be changed with order
(see EulerOrder constants). By default, the YXZ convention is used (@GlobalScope.EULER_ORDER_YXZ): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method from_euler(), this order is reversed.
Note: For this method to return correctly, the basis needs to be orthonormal (see orthonormalized()).
Note: Euler angles are much more intuitive but are not suitable for 3D math. Because of this, consider using the get_rotation_quaternion() method instead, which returns a Quaternion.
Note: In the Inspector dock, a basis's rotation is often displayed in Euler angles (in degrees), as is the case with the Node3D.rotation property.
Returns this basis's rotation as a Quaternion.
Note: Quaternions are much more suitable for 3D math but are less intuitive. For user interfaces, consider using the get_euler() method, which returns Euler angles.
Returns the length of each axis of this basis, as a Vector3. If the basis is not sheared, this value is the scaling factor. It is not affected by rotation.
Note: If the value returned by determinant() is negative, the scale is also negative.
Returns the inverse of this basis's matrix.
Returns true
if this basis is conformal. A conformal basis is both orthogonal (the axes are perpendicular to each other) and uniform (the axes share the same length). This method can be especially useful during physics calculations.
Returns true
if this basis and b
are approximately equal, by calling @GlobalScope.is_equal_approx() on all vector components.
Returns true
if this basis is finite, by calling @GlobalScope.is_finite() on all vector components.
Creates a new Basis with a rotation such that the forward axis (-Z) points towards the target
position.
By default, the -Z axis (camera forward) is treated as forward (implies +X is right). If use_model_front
is true
, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target
position.
The up axis (+Y) points as close to the up
vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see orthonormalized()).
The target
and the up
cannot be Vector3.ZERO, and shouldn't be colinear to avoid unintended rotation around local Z axis.
Returns the orthonormalized version of this basis. An orthonormal basis is both orthogonal (the axes are perpendicular to each other) and normalized (the axes have a length of 1.0
), which also means it can only represent a rotation.
It is often useful to call this method to avoid rounding errors on a rotating basis:
Returns a copy of this basis rotated around the given axis
by the given angle
(in radians).
The axis
must be a normalized vector (see Vector3.normalized()). If angle
is positive, the basis is rotated counter-clockwise around the axis.
Returns this basis with each axis's components scaled by the given scale
's components.
The basis matrix's rows are multiplied by scale
's components. This operation is a global scale (relative to the parent).
Performs a spherical-linear interpolation with the to
basis, given a weight
. Both this basis and to
should represent a rotation.
Example: Smoothly rotate a Node3D to the target basis over time, with a Tween:
Returns the transposed dot product between with
and the x axis (see transposed()).
This is equivalent to basis.x.dot(vector)
.
Returns the transposed dot product between with
and the y axis (see transposed()).
This is equivalent to basis.y.dot(vector)
.
Returns the transposed dot product between with
and the z axis (see transposed()).
This is equivalent to basis.z.dot(vector)
.
Returns the transposed version of this basis. This turns the basis matrix's columns into rows, and its rows into columns.