Previous Tutorial: Installation
Overview
This tutorial describes how to get started using Gazebo 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.cpp
file using the editor of your choice.
The easiest way to include Gazebo Math is through the gz/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 two 3D points with arbitrary values. We will use the gz::math::Vector3 class to represent these points. Gazebo Math provides a handy gz::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 point1
and point2
using the gz::math::Vector3::Distance() function and output the distance value.
To compile this code on UNIX with pkg-config, use the following command:
The program can then be run as:
Bonus: Vector2 Example
The following is an example program that uses Vector2 to perform some simple computation.