The CartesianVector class defined in C++ provides a specialized vector class derived from the Matrix class. It is designed for use in Cartesian coordinate systems and can perform all matrix operations along with several vector-specific operations. This guide provides an overview of how to interact with the CartesianVector class.
The CartesianVector Class
Description and Naming
The CartesianVector class is a templated class with two template arguments - T and L.
CartesianVector<T, L>
produces a vector of length L with elements of type T.
The two arguments are, respectively:
-
T - The type of the vector elements. This should be a floating point type.
-
L - The length of the vector. This should be an integer input.
Since the class is derived from the Matrix class, it inherits all the functionalities of the Matrix class and adds several vector-specific operations.
For a complete guide on interacting with the CartesianVector class, refer to the Doxygen documentation: CartesianVector Doxygen
Macros are defined for sizes up to 6x6. Examples provided below (not an exhaustive list). The full type definitions are found in modelspace/clockwerk/src/core/macros.h.
CartesianVector Template Arguments | Macro |
---|---|
|
|
|
|
Creating a CartesianVector
Description | C++ Example | Python Example |
---|---|---|
Default Constructor - Creates a vector filled with zeros. |
|
|
Constructor with Initial Value - Creates a vector where all elements are the same value. |
|
|
Constructor with initializer list - Creates a vector from an initializer list |
|
|
Constructor with Array - Creates a vector from an array. |
|
|
Copy Constructor - Creates a new vector as a copy of another vector. |
|
|
Setting and Getting Values
Description | C++ Example | Python Example |
---|---|---|
Setting a Value - Set the value at a specific index. |
|
|
Getting a Value - Get the value at a specific index. |
|
|
Bracket access - Directly access the value at a specific index (unsafe for embedded operations). |
|
|
Vector Operations
Description | C++ Example | Python Example |
---|---|---|
Norm of a Vector - Calculates the norm of the vector. |
|
|
Norm Squared of a Vector - Calculates the squared norm of the vector. |
|
|
Unit Vector - Returns the unitized version of the vector. |
|
|
Unitize - Unitizes the current vector. |
|
|
Normalize - Normalizes the current vector. |
|
|
Additional Operations
Description | C++ Example | Python Example |
---|---|---|
Setting All Elements to Zero - Sets all elements of the vector to zero. |
|
|
Copying a Vector - Copies the current vector to another vector. |
|
|
Vector Math Functions
Description and Naming
The vector math functions operate on the Vector
class. They have two flavors: functions which return a pass by reference and
an error code if the operation is invalid, which are typically used for embedded/safe operations, and functions
which are overloaded and more intuitive operators which return directly without an error code. The vector functions
follow a consistent naming convention:
-
Capital letters represent matrices.
-
Lowercase letters represent scalars.
-
Vectors are treated as 1-dimensional matrices.
-
Pass-by-reference return values are all named
result
. -
The letter used in the function indicates the order of operations (e.g., A/a comes first, then B/b).
Note that the non-overloaded matrix functions also can be used for the vector class.
For a complete guide on interacting with the vector math functions, refer to the Doxygen documentation: Vector Math Functions Doxygen
Dot and Cross Product
Description | C++ Example | Python Example |
---|---|---|
Dot Product - Computes the dot product of two vectors. |
|
|
Cross Product - Computes the cross product of two 3-dimensional vectors. |
|
|
Tilde Operation
Description | C++ Example | Python Example |
---|---|---|
Tilde Operator - Computes the tilde matrix of a 3-dimensional vector. |
|
|
Adding Vectors
Description | C++ Example | Python Example |
---|---|---|
Adding Two Vectors - Adds two vectors element-wise and returns the result. |
|
|
Adding a Scalar to a Vector - Adds a scalar to a vector and returns the result. |
|
|
Subtracting Vectors
Description | C++ Example | Python Example |
---|---|---|
Subtracting Two Vectors - Subtracts one vector from another element-wise and returns the result. |
|
|
Multiplying Vectors
Description | C++ Example | Python Example |
---|---|---|
Multiplying a Matrix and a Vector - Multiplies a matrix by a vector and returns the result. |
|
|
Multiplying a Scalar by a Vector - Multiplies a scalar by a vector and returns the result. |
|
|