Previous Tutorial: Installation
This tutorial describes how to get started using Ignition Math with C++.
We will run through an example that determines the distance between two points in 3D space. Start by creating a bare-bones main file using the editor of your choice.
The easiest way to include Ignition Math is through the
ignition/math.hh header file. Alternatively, you can include only the header files you need. For this example, we'll take the short and easy approach.
At this point your main file should look like
Now let's create to 3D points with arbitrary values. We will use the ignition::math::Vector3 class to represent these points. Ignition Math provides a handy ignition::math::Vector3d type which is a typedef of
Vector3<double>. The result of this addition will be a main file similar to the following.
Finally, we can compute the distance between
point2 using the ignition::math::Vector3::Distance() function and output the distance value.
Bonus: Vector2 Example
The following is an example program that uses Vector2 to perform some simple computation.