From 9f6fed51430a768aaf061727d88bdfa2355f49aa Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 6 Jan 2022 20:54:12 +0100 Subject: [PATCH 1/2] Added Python Getting started tutorial Signed-off-by: ahcorde --- tutorials.md.in | 11 +++--- tutorials/pythongetstarted.md | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tutorials/pythongetstarted.md diff --git a/tutorials.md.in b/tutorials.md.in index 31e220980..50ffc7771 100644 --- a/tutorials.md.in +++ b/tutorials.md.in @@ -9,11 +9,12 @@ Ignition @IGN_DESIGNATION_CAP@ library and how to use the library effectively. 1. \subpage install "Installation" 2. \subpage cppgetstarted "C++ Get Started" -3. \subpage vector "Vector example" -4. \subpage angle "Angle example" -5. \subpage triangle "Triangle example" -6. \subpage rotation "Rotation example" -7. \subpage color "Color example" +3. \subpage pythongetstarted "Python Get Started" +4. \subpage vector "Vector example" +5. \subpage angle "Angle example" +6. \subpage triangle "Triangle example" +7. \subpage rotation "Rotation example" +8. \subpage color "Color example" ## License diff --git a/tutorials/pythongetstarted.md b/tutorials/pythongetstarted.md new file mode 100644 index 000000000..c6279cf12 --- /dev/null +++ b/tutorials/pythongetstarted.md @@ -0,0 +1,74 @@ +\page pythongetstarted Python Get Started + +Previous Tutorial: \ref cppgetstarted + +## Overview + +This tutorial describes how to get started using Ignition Math with Python. + +**NOTE**: If you have compiled Ignition Math from source, you should export +your `PYTHONPATH`. + +```bash +export PYTHONPATH=$PYTHONPATH:/install/lib/python +``` + +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. + +```python +def main(): + pass + +if __name__ == "__main__": + main() +``` + +The easiest way to include Ignition Math is through `import ignition.math`. + +At this point your main file should look like + +```python +import ignition.math + +def main(): + pass + +if __name__ == "__main__": + main() +``` + +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 `Vector3d`. The result of this +addition will be a main file similar to the following. + +```python +from ignition.math import Vector3d + +def main(): + point1 = Vector3d(1, 3, 5) + point2 = Vector3d(2, 4, 6) + +if __name__ == "__main__": + main() +``` + +Finally, we can compute the distance between `point1` and `point2` using the +ignition.math.Vector3.Distance() function and output the distance value. + +```python +from ignition.math import Vector3d + +def main(): + point1 = Vector3d(1, 3, 5) + point2 = Vector3d(2, 4, 6) + + distance = point1.distance(point2); + + print("Distance from {} to {} is {}".format(point1, point2, distance)) + +if __name__ == "__main__": + main() +``` From 185bec5131a240b6cc18f7a37d440c759875fd9c Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 7 Jan 2022 09:29:08 +0100 Subject: [PATCH 2/2] fix tutorial Signed-off-by: ahcorde --- tutorials/pythongetstarted.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tutorials/pythongetstarted.md b/tutorials/pythongetstarted.md index c6279cf12..81593dea0 100644 --- a/tutorials/pythongetstarted.md +++ b/tutorials/pythongetstarted.md @@ -39,10 +39,11 @@ if __name__ == "__main__": main() ``` -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 `Vector3d`. The result of this -addition will be a main file similar to the following. +Now let's create two 3D points with arbitrary values. We will use the +`ignition.math.Vector3` class to represent these points. Ignition Math provides +some `Vector3` types which are: `Vector3d` (Vector3 using doubles), `Vector3f` (Vector3 using floats) +and `Vector3i` (Vector3 using integers). The result of this addition will be a +main file similar to the following. ```python from ignition.math import Vector3d @@ -56,7 +57,7 @@ if __name__ == "__main__": ``` Finally, we can compute the distance between `point1` and `point2` using the -ignition.math.Vector3.Distance() function and output the distance value. +`ignition.math.Vector3.distance()` function and output the distance value. ```python from ignition.math import Vector3d