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
CartesianVector<double, 3> v1;
CartesianVector3D v1;
CartesianVector<float, 2> v2;
CartesianVector2F v2;

Creating a CartesianVector

Description C++ Example Python Example

Default Constructor - Creates a vector filled with zeros.

CartesianVector<double, 3> vec1;
vec1 = CartesianVector3D()

Constructor with Initial Value - Creates a vector where all elements are the same value.

CartesianVector<double, 3> vec2(5); // All elements are set to 5
vec2 = CartesianVector3D(5) # All elements are set to 5

Constructor with initializer list - Creates a vector from an initializer list

CartesianVector<double, 3> vec3({1, 2, 3});
vec3 = CartesianVector3D([1, 2, 3])

Constructor with Array - Creates a vector from an array.

double initial[3] = {1, 2, 3};
CartesianVector<double, 3> vec4(initial);
initial = [1, 2, 3]
vec4 = CartesianVector3D(initial)

Copy Constructor - Creates a new vector as a copy of another vector.

CartesianVector<double, 3> vec5(vec4);
vec5 = vec4

Setting and Getting Values

Description C++ Example Python Example

Setting a Value - Set the value at a specific index.

vec1.set(0, 10); // Sets the value at index 0 to 10
vec1.set(0, 10) # Sets the value at index 0 to 10

Getting a Value - Get the value at a specific index.

double value;
vec1.get(0, value); // Retrieves the value at index 0 into variable 'value'
value = 1
vec1.get(0, value) # Retrieves the value at index 0 into variable 'value'

Bracket access - Directly access the value at a specific index (unsafe for embedded operations).

double value = vec1[0];
# No equivalent implemented in Python

Vector Operations

Description C++ Example Python Example

Norm of a Vector - Calculates the norm of the vector.

double normVal;
vec1.norm(normVal);
normVal = 0.0
vec1.norm(normVal)

Norm Squared of a Vector - Calculates the squared norm of the vector.

double normSquaredVal;
vec1.normSquared(normSquaredVal);
normSquaredVal = 0.0
vec1.normSquared(normSquaredVal)

Unit Vector - Returns the unitized version of the vector.

CartesianVector<double, 3> unitVec;
vec1.unit(unitVec);
unitVec = CartesianVector3D()
vec1.unit(unitVec)

Unitize - Unitizes the current vector.

vec1.unitize();
vec1.unitize()

Normalize - Normalizes the current vector.

vec1.normalize();
vec1.normalize()

Additional Operations

Description C++ Example Python Example

Setting All Elements to Zero - Sets all elements of the vector to zero.

vec1.setToZeros();
vec1.setToZeros()

Copying a Vector - Copies the current vector to another vector.

CartesianVector<double, 3> copyVec;
vec1.getCopy(copyVec);
copyVec = CartesianVector3D()
vec1.getCopy(copyVec)

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.

CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> b({1.0, 2.0, 3.0});
double result;
dot(a, b, result);
# Python example not available

Cross Product - Computes the cross product of two 3-dimensional vectors.

CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> b({1.0, 2.0, 3.0});
CartesianVector<double, 3> result;
cross(a, b, result);
# Python example not available

Tilde Operation

Description C++ Example Python Example

Tilde Operator - Computes the tilde matrix of a 3-dimensional vector.

CartesianVector<double, 3> v({1.0, 2.0, 3.0});
Matrix<double, 3, 3> result;
tilde(v, result);
# Python example not available

Adding Vectors

Description C++ Example Python Example

Adding Two Vectors - Adds two vectors element-wise and returns the result.

CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> b({1.0, 2.0, 3.0});
CartesianVector<double, 3> result = a + b;
# Python example not available

Adding a Scalar to a Vector - Adds a scalar to a vector and returns the result.

double scalar = 2.0;
CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> result = scalar + a;
# Python example not available

Subtracting Vectors

Description C++ Example Python Example

Subtracting Two Vectors - Subtracts one vector from another element-wise and returns the result.

CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> b({1.0, 2.0, 3.0});
CartesianVector<double, 3> result = a - b;
# Python example not available

Multiplying Vectors

Description C++ Example Python Example

Multiplying a Matrix and a Vector - Multiplies a matrix by a vector and returns the result.

Matrix<double, 3, 3> A({{1.0, 2.0, 3.0}, {1.0, 2.0, 3.0}, {1.0, 2.0, 3.0}});
CartesianVector<double, 3> b({1.0, 2.0, 3.0});
CartesianVector<double, 3> result = A * b;
# Python example not available

Multiplying a Scalar by a Vector - Multiplies a scalar by a vector and returns the result.

double scalar = 2.0;
CartesianVector<double, 3> a({1.0, 2.0, 3.0});
CartesianVector<double, 3> result = scalar * a;
# Python example not available