diff --git a/tutorials/angle.md b/tutorials/angle.md deleted file mode 100644 index ad468160..00000000 --- a/tutorials/angle.md +++ /dev/null @@ -1,122 +0,0 @@ -\page angle Angle example - -This tutorial explains how to use the `Angle` class from Gazebo Math library. - -## C++ example - -### Compile the code - -Go to `gz-math/examples` and use `cmake` to compile the code: - -```{.sh} -git clone https://github.com/gazebosim/gz-math/ -b gz-math8 -cd gz-math/examples -mkdir build -cd build -cmake .. -make -``` - -When the code is compiled, run: - -```{.sh} -./angle_example -``` - -The ouput of the program: - -```{.sh} -The angle 'a' should be zero: 0 -Pi in radians: 3.14159 -Pi in degrees: 180 -Pi + PI/2 in radians: 4.71239 -Normalized to the range -Pi and Pi: -1.5708 -``` - -### Code - -The code instantiates an angle class. The default constructed angle should be zero. - -\snippet examples/angle_example.cc Create an angle - -There are some predefined angles, such as: - -\snippet examples/angle_example.cc constant pi - -By default, all values are in radians, but you can use the method `Degree` to convert to degrees. - -\snippet examples/angle_example.cc Output the angle in radians and degrees. - -The `Angle` class overloads the `+=`, and many other, math operators. - -\snippet examples/angle_example.cc The Angle class overloads the +=, and many other, math operators. - -Use the method `Normalized` to bound the value between `-PI` and `PI`. - -\snippet examples/angle_example.cc normalized - -## Ruby example - -This example will only work if the Ruby interface library was compiled and installed. For example, -on Ubuntu: - -```{.sh} -sudo apt install ruby-gz-math<#> -``` - -Modify the `RUBYLIB` environment variable to include the Gazebo Math library install path. For example, if you install to `/usr`: - -```{.sh} -export RUBYLIB=/usr/lib/ruby:$RUBYLIB -``` - -Move to the examples folder: - -```{.sh} -cd examples -``` - -Execute the code: - -```{.sh} -ruby angle_example.rb -``` - -### Code - -There are some predefined values: - -```{.rb} -printf("PI in degrees = %f\n", Gz::Math::Angle.Pi.Degree) -``` - -Create new objects: - -```{.rb} -a1 = Gz::Math::Angle.new(1.5707) -a2 = Gz::Math::Angle.new(0.7854) -``` - -Use the values in radians or degrees: - -```{.rb} -printf("a1 = %f radians, %f degrees\n", a1.Radian, a1.Degree) -printf("a2 = %f radians, %f degrees\n", a2.Radian, a2.Degree) -``` - -The `Angle` class overloads math operators. - -```{.rb} -printf("a1 * a2 = %f radians, %f degrees\n", (a1 * a2).Radian, (a1 * a2).Degree) -printf("a1 + a2 = %f radians, %f degrees\n", (a1 + a2).Radian, (a1 + a2).Degree) -printf("a1 - a2 = %f radians, %f degrees\n", (a1 - a2).Radian, (a1 - a2).Degree) -``` - -Normalize the value between `-PI` and `PI`. - -```{.rb} -a3 = Gz::Math::Angle.new(15.707) -printf("a3 = %f radians, %f degrees\n", a3.Radian, a3.Degree) -a3.Normalize -printf("a3.Normalize = %f radians, %f degrees\n", a3.Radian, a3.Degree) -``` diff --git a/tutorials/color.md b/tutorials/color.md index 92ea8a3f..b209309b 100644 --- a/tutorials/color.md +++ b/tutorials/color.md @@ -54,4 +54,4 @@ You can also set or read a color in HSV. \snippet examples/color_example.cc Set value from HSV -There are more functions in `Color`. Take a look at the [API](https://gazebosim.org/api/math/7/classgz_1_1math_1_1Color.html) +There are more functions in `Color`. Take a look at the [API](https://gazebosim.org/api/math/8/classgz_1_1math_1_1Color.html) diff --git a/tutorials/example_triangle.md b/tutorials/example_triangle.md index 9d931ccd..2226a12c 100644 --- a/tutorials/example_triangle.md +++ b/tutorials/example_triangle.md @@ -69,4 +69,4 @@ The `Intersects` function checks if a line segment intersects the triangle. It a \snippet examples/triangle_example.cc intersect -There are more functions in `Triangle`. Take a look at the [API](https://gazebosim.org/api/math/7/) +There are more functions in `Triangle`. Take a look at the [API](https://gazebosim.org/api/math/8/) diff --git a/tutorials/rotation.md b/tutorials/rotation.md deleted file mode 100644 index 7bcdb068..00000000 --- a/tutorials/rotation.md +++ /dev/null @@ -1,104 +0,0 @@ -\page rotation Rotation example - -This example explains how to use quaternions and euler angles, and how to convert between them. - -## Compiling and running the code - -Go to `gz-math/examples` and use `cmake` to compile the code: - -```{.sh} -git clone https://github.com/gazebosim/gz-math/ -b gz-math8 -cd gz-math/examples -mkdir build -cd build -cmake .. -make -``` - -When the code is compiled, you can run two different examples, one which converts from quaternion to euler angles: - -```{.sh} -Usage: - ./quaternion_to_euler - -Example - ./quaternion_to_euler 0.5 0.5 0.5 0.5 -``` - -And the other which converts from euler to quaternion: - -```{.sh} -Usage (angles specified in radians): - quaternion_from_euler - -Example - quaternion_from_euler 0 0 1.57 -``` - -The ouput of each program, respectively: - -```{.sh} -./quaternion_to_euler 0.5 0.5 0.5 0.5 -Normalizing Quaternion components: - W 0.5 - X 0.5 - Y 0.5 - Z 0.5 -to - W 0.5 - X 0.5 - Y 0.5 - Z 0.5 - -Converting to Euler angles - roll 1.570796 radians - pitch -0.000000 radians - yaw 1.570796 radians - - roll 90.000000 degrees - pitch -0.000000 degrees - yaw 90.000000 degrees - -to Rotation matrix - 0.000000 0.000000 1.000000 - 1.000000 0.000000 0.000000 - 0.000000 1.000000 0.000000 -``` - -```{.sh} -./quaternion_from_euler 0 0 1.57 -Converting Euler angles: - roll 0.000000 radians - pitch 0.000000 radians - yaw 1.570000 radians - - roll 0.000000 degrees - pitch 0.000000 degrees - yaw 89.954374 degrees - -to Quaternion - W 0.707388 - X 0.000000 - Y 0.000000 - Z 0.706825 - -to Rotation matrix - 0.000796 -1.000000 0.000000 - 1.000000 0.000796 0.000000 - 0.000000 0.000000 1.000000 -``` - -## Code - -You can create some objects to express rotations: - -\snippet examples/quaternion_from_euler.cc constructor -\snippet examples/quaternion_to_euler.cc constructor - -To access the quaterions attributes: - -\snippet examples/quaternion_from_euler.cc access quaterion - -Or to acccess the rotation matrix elements: - -\snippet examples/quaternion_from_euler.cc rotation matrix diff --git a/tutorials/triangle.md b/tutorials/triangle.md deleted file mode 100644 index a2580cce..00000000 --- a/tutorials/triangle.md +++ /dev/null @@ -1,72 +0,0 @@ -\page triangle Triangle example - -This tutorial explains how to use the `Triangle` class from Gazebo Math library. - -## Compile the code - -Go to `gz-math/examples` and use `cmake` to compile the code: - -```{.sh} -git clone https://github.com/gazebosim/gz-math/ -b gz-math8 -cd gz-math/examples -mkdir build -cd build -cmake .. -make -``` - -When the code is compiled, run: - -```{.sh} -./triangle_example -``` - -The ouput of the program: - -```{.sh} -Vertex 1: -1 0 -Vertex 2: 0 1 -Vertex 3: 1 0 -Side 1: -1 0 0 1 -Side 2: 0 1 1 0 -Side 3: 1 0 -1 0 -Perimeter=4.82843 Area=1 -Triangle contains the point 0, 0.5 -A line from (-2, 0.5) to (2, 0.5) intersects the triangle at the -following points: - Pt1=-0.5 0.5 - Pt2=0.5 0.5 -``` - -## Code - -Create a triangle with the following vertices: - -\snippet examples/triangle_example.cc constructor - -The individual vertices are accessible through the `[]` operator. - -\snippet examples/triangle_example.cc access1 - -Each side of the triangle is also accessible via the `Side` method. Each side consists of 2 vertices, the following code will print out the X and Y values of each vertex. - -\snippet examples/triangle_example.cc access2 - -It's also possible to set each vertex individually or set all the vertices at once. - -\snippet examples/triangle_example.cc vertex1 -\snippet examples/triangle_example.cc vertex2 - -You can get the perimeter length and area of the triangle - -\snippet examples/triangle_example.cc perimeter and area - -The `Contains` function checks if a line or point is inside the triangle. - -\snippet examples/triangle_example.cc contains - -The `Intersects` function checks if a line segment intersects the triangle. It also returns the points of intersection. - -\snippet examples/triangle_example.cc intersect - -There are more functions in `Triangle`. Take a look at the [API](https://gazebosim.org/api/math/6.4/index.html) diff --git a/tutorials/vector.md b/tutorials/vector.md deleted file mode 100644 index f32df135..00000000 --- a/tutorials/vector.md +++ /dev/null @@ -1,145 +0,0 @@ -\page vector Vector example - -This tutorial explains how to use the `Vector` classes from Gazebo Math library. - -## C++ example - -### Compile the code - -To compile the code, go to `gz-math/examples` and use `cmake`: - -```{.sh} -git clone https://github.com/gazebosim/gz-math/ -b gz-math8 -cd gz-math/examples -mkdir build -cd build -cmake .. -make -``` - -When the code is compiled, run: - -```{.sh} -./vector2_example -``` - -The ouput of the program: - -```{.sh} -Vec2: 2 4 -Vec2a: 1 2 -Vec2b: 1.2 3.4 -Vec2: x=2 y=4 -Vec2a: x=1 y=2 -Vec2b: x=1.2 y=3.4 -4 -2 8 -3 6 -1 2 -2 2 -2.23607 -``` - -### Code - -Create a `Vector2` called `vec2` of doubles using the typedef `Vector2d`. **The initial x and y values are zero**. The x and y component of `vec2` can be set at anytime. - -\snippet examples/vector2_example.cc constructor - - -The `Vector2` class is a template, so you can also create a `Vector2` using `gz::math::Vector2`: - -\snippet examples/vector2_example.cc constructor2 - -It's also possible to set initial values. Here we are using a `Vector2` of floats: - -\snippet examples/vector2_example.cc constructor3 - -We can output the contents of each vector using `std::cout`. - -\snippet examples/vector2_example.cc stdout - -You can also get access to each component in the vector using the `X()`, `Y()` accessors or the `[]` operator, The operator is clamped to the range `[0, 1]`. - -\snippet examples/vector2_example.cc access - -The `Vector2` class overloads many common operators, such as: - -\snippet examples/vector2_example.cc operators - -There are also many useful function such as finding the distance between two vectors. - -\snippet examples/vector2_example.cc distance - -**There are more functions in Vector2. Take a look at the [API](https://gazebosim.org/libs/math)** - -## Ruby examples - -This example will only work if the Ruby interface library was compiled and installed. For example, -on Ubuntu: - -```{.sh} -sudo apt install ruby-gz-math<#> -``` - -Modify the `RUBYLIB` environment variable to include the Gazebo Math library install path. For example, if you install to `/usr`: - -```{.sh} -export RUBYLIB=/usr/lib/ruby:$RUBYLIB -``` - -Move to the examples folder: - -```{.sh} -cd examples -``` - -Execute the examples: - -```{.sh} -ruby vector2_example.rb -ruby vector3_example.rb -``` - -### Code - -Create a `Vector2` of doubles using the typedef `Vector2d`. It's possible to set initial values or use another object to create a identical copy. - -```{.rb} -va = Gz::Math::Vector2d.new(1, 2) -``` - -You can get access to each component in the vector using the `X()`, `Y()` accessors. - -```{.rb} -printf("va = %f %f\n", va.X(), va.Y()) -printf("vb = %f %f\n", vb.X(), vb.Y()) -printf("vc = %f %f\n", vc.X(), vc.Y()) -``` - -The `Vector2` class overloads many common operators, such as: - -```{.rb} -vb += va -printf("vb += va: %f %f\n", vb.X(), vb.Y()) -``` - -There are also many useful functions, such as finding the distance between two vectors or normalizing a vector. - -```{.rb} -vb.Normalize -printf("vb.Normalize = %f %f\n", vb.X(), vb.Y()) -printf("vb.Distance(va) = %f\n", vb.Distance(va)) -``` - -You can create vectors with 3 dimensions using the typedef `Vector3d`: - -```{.rb} -v1 = Gz::Math::Vector3d.new(0, 0, 0) -``` - -You can also get access to each component in the vector using the `X()`, `Y()` and `Z()` accessors: - -```{.rb} -printf("v =: %f %f %f\n", v1.X(), v1.Y(), v1.Z()) -```