summaryrefslogtreecommitdiff
path: root/PVCM/cama/fr/ma25 Drones -- Exercice.ipynb
diff options
context:
space:
mode:
authormartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
committermartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
commit66c3bbfa94d8a41e58adf154be25e6d86fee8e30 (patch)
tree9c5e998f324f2f60c1717759144da3f996c5ae1a /PVCM/cama/fr/ma25 Drones -- Exercice.ipynb
init: initial commit
Diffstat (limited to 'PVCM/cama/fr/ma25 Drones -- Exercice.ipynb')
-rw-r--r--PVCM/cama/fr/ma25 Drones -- Exercice.ipynb295
1 files changed, 295 insertions, 0 deletions
diff --git a/PVCM/cama/fr/ma25 Drones -- Exercice.ipynb b/PVCM/cama/fr/ma25 Drones -- Exercice.ipynb
new file mode 100644
index 0000000..019ce93
--- /dev/null
+++ b/PVCM/cama/fr/ma25 Drones -- Exercice.ipynb
@@ -0,0 +1,295 @@
+{
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5,
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "3235ec05",
+ "metadata": {
+ "lang": "fr"
+ },
+ "source": [
+ "# Spectacle de drones\n",
+ "\n",
+ "<img src=\"images/drone_boat.png\"/>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "630fb2b1",
+ "metadata": {
+ "lang": "fr"
+ },
+ "source": [
+ "Le but est de faire un joli spectacle nocturne. \n",
+ "\n",
+ "On a un ensemble de 100 drones qui forment l'image d'un bateau en 3D. Pour nous il s'agit d'un ensemble de points 3D (centre de gravité de chaque drone) qu'on range dans un tableau Numpy 3 par 100. Le bateau tient dans un cube de 20x20x20. \n",
+ "\n",
+ "Initialement \n",
+ "\n",
+ "* l'ensemble des drones est centré en (0,0,0) donc si on veut positionner le bateau en (10, 20, 200) il faut faire une translation d'autant sur l'ensemble des drones.\n",
+ "* l'axe principal du bateau est l'axe de x c.a.d que l'avant du bateau est en x=10 et l'arrière en x=-10."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "58dcf259",
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-03-25T09:43:59.562566Z",
+ "start_time": "2024-03-25T09:43:59.487939Z"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[-20., 20., 0., 0., 0., 0., 0.],\n",
+ " [ 0., 0., 0., 0., 0., -10., 10.],\n",
+ " [ 0., 0., -5., 5., 0., 0., 0.]])"
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "#boat = np.random.randint(-100, 100, size=(3,10)) / 10 # with a little luck...\n",
+ "\n",
+ "# A formation that allows for easier debugging\n",
+ "\n",
+ "boat = np.array([[-20., 0., 0.],\n",
+ " [ 20., 0., 0.],\n",
+ " [ 0., 0., -5.],\n",
+ " [ 0., 0., 5.],\n",
+ " [ 0., 0., 0.],\n",
+ " [ 0., -10., 0.],\n",
+ " [ 0., 10., 0.],\n",
+ " ])\n",
+ "boat = boat.T\n",
+ "boat"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "311abaaa",
+ "metadata": {
+ "lang": "fr"
+ },
+ "source": [
+ "On désire déplacer le bateau dans le ciel en lui faisant faire des figures (les unités utilisées sont le mètre et la seconde). Tous les mouvements sont décomposés seconde par seconde c.a.d. qu'on donne la position de tous les drones à chaque seconde (un autre programme se débrouille pour déplacer les drones à leur position suivante).\n",
+ "\n",
+ "### Figure 1\n",
+ "\n",
+ "Faire tourner le bateau (donc l'ensemble des drones) à l'horizontal autour du point (0,0,80) à une distance de 100 m. Il fait un tour complet en 5 minutes. \n",
+ "\n",
+ "On fera attention à ce que l'orientation du bateau suive le mouvement, c.a.d. que l'avant du bateau soit toujours bien orientée. \n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4818926d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "\n",
+ "def circle(boat, t):\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "35cc29f4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Code to display\n",
+ "# Do not touch this unless you know what you are doing\n",
+ "import matplotlib.animation\n",
+ "import matplotlib.pyplot as plt\n",
+ "from matplotlib.patches import Circle\n",
+ "from matplotlib.transforms import Affine2D\n",
+ "import mpl_toolkits.mplot3d.art3d as art3d\n",
+ "matplotlib.rcParams['animation.embed_limit'] = 256 # 256mb max animation size\n",
+ "\n",
+ "plt.rcParams[\"animation.html\"] = \"jshtml\"\n",
+ "plt.rcParams['figure.dpi'] = 100 \n",
+ "plt.ioff()\n",
+ "fig = plt.figure()\n",
+ "ax = fig.add_subplot(projection='3d')\n",
+ "\n",
+ "# 5min -> 300 sec;\n",
+ "FRAMEPERSEC = 1.\n",
+ "\n",
+ "def animate(t):\n",
+ " boat_prime = circle(boat_start, t/FRAMEPERSEC)\n",
+ " plt.cla()\n",
+ " p = Circle((0, 0), 100, fill=False)\n",
+ " ax.add_patch(p)\n",
+ " art3d.pathpatch_2d_to_3d(p, z=80, zdir=\"z\")\n",
+ " plt.plot(boat_prime[0,:], boat_prime[1,:], boat_prime[2,:], '.b')\n",
+ " ax.set_xlim([-120, 120])\n",
+ " ax.set_ylim([-120, 120])\n",
+ " ax.set_zlim([0, 120]) # alternative\n",
+ " ax.set_xlabel(\"x\")\n",
+ " ax.set_ylabel(\"y\")\n",
+ " ax.set_zlabel(\"z\")\n",
+ " ax.set_title(f\"t: {t} sec\")\n",
+ "\n",
+ "\n",
+ "matplotlib.animation.FuncAnimation(fig, animate, frames=int(300*FRAMEPERSEC))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2318d7f5",
+ "metadata": {
+ "lang": "fr"
+ },
+ "source": [
+ "### Figure 2\n",
+ "\n",
+ "On désire faire tourner le bateau sur son axe principal (l'axe des x) jusqu'à revenir à la position d'origine. En aviation on appelle cela faire un tonneau (rotation de 360 sur l'axe du roulis). Écrire la fonction `barrel_roll(boat, T, t)` qui retourne la position de chaque drone, à l'instant `t` si un tour complet dure `T`seconds."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3bbdb81d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "\n",
+ "def barrel_rool(boat, T, t):\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3861ca65",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Code to display\n",
+ "# You can change this\n",
+ "Tcomplete = 20\n",
+ "\n",
+ "\n",
+ "fig = plt.figure()\n",
+ "ax = fig.add_subplot(projection='3d')\n",
+ "\n",
+ "# Do not touch this unless you know what you are doing\n",
+ "def animate2(t):\n",
+ " boat_prime = barrel_roll(boat, Tcomplete, t)\n",
+ " plt.cla()\n",
+ " plt.plot(boat_prime[0,:], boat_prime[1,:], boat_prime[2,:], '.b')\n",
+ " ax.set_xlim([-60, 60])\n",
+ " ax.set_ylim([-60, 60])\n",
+ " ax.set_zlim([-60, 60])\n",
+ " ax.set_xlabel(\"x\")\n",
+ " ax.set_ylabel(\"y\")\n",
+ " ax.set_zlabel(\"z\")\n",
+ " ax.set_title(f\"t: {t} sec\")\n",
+ "\n",
+ "# One frame per second for 2 complete rolls\n",
+ "matplotlib.animation.FuncAnimation(fig, animate2, frames=2*Tcomplete)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "65cfd841",
+ "metadata": {
+ "lang": "fr"
+ },
+ "source": [
+ "### Figure 3\n",
+ "\n",
+ "Combiner les figures 1 et 2 pour que le bateau fasse un tonneau en 10 secondes toutes les 30 secondes."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "fc7aed8e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "\n",
+ "def combined_move(boat, t):\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "d2265fd3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Code to display\n",
+ "# Do not touch this unless you know what you are doing\n",
+ "fig = plt.figure()\n",
+ "ax = fig.add_subplot(projection='3d')\n",
+ "\n",
+ "def animate3(t):\n",
+ " boat_prime = combined_move(boat, t/FRAMEPERSEC)\n",
+ " plt.cla()\n",
+ " p = Circle((0, 0), 100, fill=False)\n",
+ " ax.add_patch(p)\n",
+ " art3d.pathpatch_2d_to_3d(p, z=80, zdir=\"z\")\n",
+ " plt.plot(boat_prime[0,:], boat_prime[1,:], boat_prime[2,:], '.b')\n",
+ " ax.set_xlim([-120, 120])\n",
+ " ax.set_ylim([-120, 120])\n",
+ " ax.set_zlim([0, 120])\n",
+ " ax.set_xlabel(\"x\")\n",
+ " ax.set_ylabel(\"y\")\n",
+ " ax.set_zlabel(\"z\")\n",
+ " ax.set_title(f\"t: {t} sec\")\n",
+ "\n",
+ "# 5min -> 300 sec\n",
+ "matplotlib.animation.FuncAnimation(fig, animate3, frames=int(300*FRAMEPERSEC))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7c2da47f",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2f9122e6-899e-4afa-a49a-992e48e99647",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ]
+} \ No newline at end of file