Google.com

Motion in Space. C++ Approach

Markus Buchholz
5 min readJan 4, 2023

--

The purpose of this article is to demonstrate general mathematical operations and relations to describe particle motion in 3D space.
The theoretical background, expressed by equations plays a fundamental role to define paths and motions of objects moving in a plane or in space. I will also specify also scalars that quantify the turning and twisting in the path of a particle moving in space. Additionally, we will take a look at how to compute arc length.

The equations and simple computation operation I deployed in C++. Source files (equations and 3D curves) you will find on my GitHub.

The curve in space can be represented in vector form as follows,

where the f(t), g(t), and h(t) are component functions.

The position vector of the particle P (by author)

We can plot simple (I used these curves for running some demos ) curves of some sample vectors (see my GitHub).

curve 1 (by author)
curve 2 (by author)

If we derive the r(t) vector, which specifies the position of a particle moving along a curve in space and that f(t), g(t), and h(t) are differentiable functions of t so we can elaborate a definition of the velocity vector (direction of motion).

As ∆t approaches 0, point B approaches point along curve C.
The most important here especially for robot application is to guarantee velocity vector ≠ 0 since the condition guarantees a smooth curve along the robot motion.

For the purpose of this article (C++ code) I derive the r(t) vector using the numerical method (see my article).

The magnitude of the velocity vector is speed. The speed is calculated as follows,

As expected if we derive the vector of velocity we receive the vector of the acceleration vector. Deriving the acceleration vector we receive the jerk vector (all operations in C++)

If the particle motion along a space curve is defined in the Cartesian coordinate system {i, j, and k} coordinate system — by previously defined vectors, the best way to represent motion from the particle “point of view” — you can imagine the drone (or passengers in the airplane) is to represent forward direction motion (vector T — tangential component of acceleration vector) and the tendency of curve twist (vector N normal component of acceleration vector). We can introduce the relationship between these two vectors (B — binormal vector), as follows

Binominal vector (by author)
Components of acceleration (by author)

As a particle moves along a curve in space, the vector turns as the curve
bends (curve profile). Since T is a unit vector, its length remains constant and only its direction changes as the particle moves along the curve. We can measure this bend by the curve curvature factor,

The torsion measures how the curve bend (twist). In order to compute the torsion we need to derive the binomial vector B (along the path the particle moves)

Torsion and curvature (by author)

The most common formula to compute the torsion is given in the determinant form (see the implementation in C++)

The length of the arc on the particular curve is defined as follows

As you can see there is an integral of the speed between points a and b. In C++ I calculated integral using the trapezoid rule of integration.

Illustration of arc (by author)

For demo purposes, I use the vector,

however, for the arc length, I used a vector,

here are the results (motion_in_space.cpp):

sample results (by author)

Plotting requires (3D curves) incorporating the header file which has to be in the same folder as your cpp (a file you can clone from my repository).
Your program can be compiled as follows,

//compile
g++ my_prog.cpp -o my_prog -I/usr/include/python3.8 -lpython3.8//

//run
./my_prog

//folder tree

├── my_prog
├── my_prog.cpp
├── matplotlibcpp.h

Thank you for reading.

--

--

Markus Buchholz
Markus Buchholz

Written by Markus Buchholz

Researcher in underwater robotics

Responses (1)