modelowanie_geometryczne_23_24/jupyter/.ipynb_checkpoints/parametric_curves_1-checkpoint.ipynb

1304 lines
334 KiB
Plaintext
Raw Normal View History

2023-11-18 22:31:43 +01:00
{
"cells": [
{
"cell_type": "markdown",
"id": "1b1c1dc2",
"metadata": {},
"source": [
"\\textbf{Copyright:} Wojciech Kowalewski WMiI UAM\n",
"\n",
"\\textbf{Kurs}: Modelowanie geometryczne 2021/22\n",
"\n",
"---\n",
"---\n",
"# Modelowanie geometryczne\n",
"---\n",
"---\n",
"# I. Modelowanie parametryczne"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e2b5e255",
"metadata": {
"deletable": false,
"editable": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import math\n",
"import ipywidgets as widgets"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b306a0ae",
"metadata": {
"deletable": false,
"editable": false
},
"outputs": [],
"source": [
"def dot(a,b):\n",
" \"\"\"\n",
" a,b: wektory\n",
" \"\"\"\n",
" assert len(a)==len(b), \"Nierówne długosci wektrów\"\n",
" res = 0\n",
" for i in range(len(a)):\n",
" res += a[i]*b[i]\n",
" return res"
]
},
{
"cell_type": "markdown",
"id": "5ed3ebee",
"metadata": {},
"source": [
"## 1. Krzywe Hermite'a stopnia 3\n",
"======================================"
]
},
{
"cell_type": "markdown",
"id": "e7502ecf",
"metadata": {},
"source": [
"### 1.1. Macierz funkcji bazowych"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9a0525f7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[2.0, -3.0, 0.0, 1.0],\n",
" [-2.0, 3.0, 0.0, 0.0],\n",
" [1.0, -2.0, 1.0, 0.0],\n",
" [1.0, -1.0, 0.0, 0.0]]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hermite_basis_matrix_2D = [\n",
" [2.0,-3.0,0.0,1.0],\n",
" [-2.0,3.0,0.0,0.0],\n",
" [1.0,-2.0,1.0,0.0],\n",
" [1.0,-1.0,0.0,0.0]\n",
"]\n",
"hermite_basis_matrix_2D"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "27713848",
"metadata": {},
"outputs": [],
"source": [
"hermite_basis_function_2D = []\n",
"hermite_basis_function_2D.append(\n",
" lambda t: hermite_basis_matrix_2D[0][0]*t**3 + hermite_basis_matrix_2D[0][1]*t**2 + hermite_basis_matrix_2D[0][2]*t + hermite_basis_matrix_2D[0][3],\n",
") \n",
"hermite_basis_function_2D.append(\n",
"lambda t: hermite_basis_matrix_2D[1][0]*t**3 + hermite_basis_matrix_2D[1][1]*t**2 + hermite_basis_matrix_2D[1][2]*t + hermite_basis_matrix_2D[1][3]\n",
")\n",
"hermite_basis_function_2D.append(\n",
" lambda t: hermite_basis_matrix_2D[2][0]*t**3 + hermite_basis_matrix_2D[2][1]*t**2 + hermite_basis_matrix_2D[2][2]*t + hermite_basis_matrix_2D[2][3]\n",
")\n",
"hermite_basis_function_2D.append(\n",
"lambda t: hermite_basis_matrix_2D[3][0]*t**3 + hermite_basis_matrix_2D[3][1]*t**2 + hermite_basis_matrix_2D[3][2]*t + hermite_basis_matrix_2D[3][3]\n",
")\n"
]
},
{
"cell_type": "markdown",
"id": "19dd701d",
"metadata": {},
"source": [
"### 1.2. Wykresy funkcji bazowych"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7b1508e0",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0YAAANCCAYAAABCtdwOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAD6TElEQVR4nOzdd3wT9ePH8VeS7k1bVtkge1M2sgRRBMTBnoKDoSCiqLjF9XXjAkVlI0NwoKIyFAXZG9l7F2gLbelMm/v9EelPBLSFppe07+fj0QeX6y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hSpMgV9/vP0QurV68OON8B+uf6fx5jObVq1Sri4+MZOHDgJXkdDge33nor69evd9kphyIi10un0omI5KHq1avn2eALERERl9z29fUFIDU19ZL1e/fu5dy5c9x///1XHB777NmzREVFYbXm7m9hp0+fZv/+/Xh7e1/x87Gxsf/5GMWLF79sXYkSJQBnoQNYt24dHTp0oE2bNnz66aeULl0aHx8fvvnmG1555ZXLvt6kpCRuu+027HY7P/74I6Ghodmfi4uLw8vLi6JFi15yH4vFQokSJbL3CdC+fXteeuklkpOTWbp0KTfddBMRERFER0ezdOlSKlasyKFDh3jxxRfz9HtitVqveoz88znK7f5Klix51f2Gh4dfcvtimbzS+rS0tKs+zr85ffo0AN26dbvqNvHx8QQGBl7T44uIuJKKkYhIPvH19SU9Pf2y9X//Zf1aNGvWjO7du3PvvfcCMHHixEt+wS5atCgrV67E4XDkqhxFRkbi7+/P5MmTr/r5/3LxF+W/i4mJAf6/+M2ZMwdvb2++//57/Pz8srf75ptvLruv3W7n7rvv5sCBA6xYseKSIaQvPmZmZiZnz569pBwZhkFMTAyNGjXKXteuXTueffZZfv/9d5YtW5Y9WEW7du1YvHgxFSpUyL7996/5er8nuZHb/eXk+iZXupjngw8+uOpIdlcqyyIi7kDFSEQkn5QvX55t27Zdsu6XX37hwoUL1/3YAwcOJDAwkD59+pCcnMy0adOw2WwAdOzYkdmzZzN16tRcnU7XuXNnXn31VSIiIrJLQm4lJSWxcOHCS06n++KLL7BarbRq1Qpw/jLv5eWVnRec74rNmDHjsse79957Wb58OT/++GP2qYV/165dO9544w1mzpzJI488kr1+wYIFJCcnX1JyGjduTEhICOPHjycmJoabb74ZcL6T9PrrrzNv3jxq1KhxyTxUefE9yY383l9OXe3dyxYtWhAWFsbOnTt56KGHzIgmInLNVIxERPJJ//79efbZZ3nuuedo3bo1O3fu5MMPP7zkVLDr0a1bNwICAujWrRupqanMnj0bHx8fevfuzZQpUxg6dCh79uyhbdu2OBwO1q5dS/Xq1enVq9cVH2/UqFEsWLCAVq1a8cgjj1CnTh0cDgdHjx5l8eLFPProozRp0uRfM0VERDBs2DCOHj1KlSpVWLRoEZ9++inDhg3LHoGuU6dOvPPOO/Tp04cHHniAuLg43nrrrexfvi968803mTFjBiNGjCAwMJA1a9Zkfy4kJIQaNWpw8803c8stt/DEE0+QmJhIixYtskelq1+/Pv3798++j81mo3Xr1nz33XdUqFAhe1S1Fi1a4Ovry7Jlyxg5cmSef09yI7/3l1MXT9mcNGkSwcHB+Pn5UaFCBSIiIvjggw8YOHAg8fHxdOvWjWLFinH27Fm2bt3K2bNnmThxYr7nFRHJCRUjEZF8MmbMGBITE5k6dSpvvfUWjRs3Zt68eXTt2jXP9nHbbbexaNEiunTpQteuXfnqq6/w9/dn0aJFvPbaa8yePZvx48cTHBx
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Funkcje bazowe Hermite\")\n",
"\n",
"for n in range(4):\n",
" ax.plot(t,hermite_basis_function_2D[n](t) , label=\"h_\"+str(n)+\"(t)\")\n",
"\n",
"leg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"leg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c411dee2",
"metadata": {},
"outputs": [],
"source": [
"def find_ext(x,y, lp, lk):\n",
" t = np.arange(lp, lk, 0.001)\n",
" xmin = xmax = x(lp)\n",
" ymin = ymax = y(lp)\n",
" for p in t:\n",
" if x(p) < xmin:\n",
" xmin = x(p)\n",
" else:\n",
" if x(p) > xmax:\n",
" xmax = x(p)\n",
" if y(p) < ymin:\n",
" ymin = y(p)\n",
" else:\n",
" if y(p) > ymax:\n",
" ymax = y(p)\n",
" return [[xmin,xmax],[ymin,ymax]]"
]
},
{
"cell_type": "markdown",
"id": "c446ac17",
"metadata": {},
"source": [
"### 1.3. Przykłady\n",
"\n",
"#### 1.3.1. Przykład 1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e1a529b0",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhoAAANCCAYAAAAgE2UIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAABPyklEQVR4nO3df5xNdeLH8fedMcYMZmQmImPIrlKIspshRRkWKZVop8RSrb5UopLaMqOs0g9sLdsP6cfuLMqPSpLph1Fko9hKPxVRfjWKkR/jmjnfP+7OMObXvTP3nHPPOa/n4+ExM+eee8/H596al3PPPcdnGIYhAAAAE0TZPQAAAOBehAYAADANoQEAAExDaAAAANMQGgAAwDSEBgAAMA2hAQAATENoAAAA0xAaAADANIQGHOM///mPLr/8cjVv3lyxsbFq3Lix0tLSNG7cOLuHZrmDBw8qMzNTK1asCGr9FStWyOfz6eWXXzZ3YBGiRYsWGjZsWFDrXXLJJeXetm7dOvl8Pj333HPhHVwNFT+Xxz/3S5cuVWZmZo0ed9iwYerevXuNHgMoD6EBR3j99dfVpUsX5efna+rUqVq+fLlmzJihrl27at68eXYPz3IHDx5UVlZW0KHhNYsWLdK9995r9zBMcc455+iDDz7QOeecU7Js6dKlysrKsnFUQMVq2T0AIBhTp05Vy5Yt9eabb6pWrWMv26uvvlpTp061cWTud/DgQcXHx9s9jJB07NjR7iGU4ff75fP5Sr1+qyMhIUGdO3cO06gA87FHA46wZ88eJScnl/s/6aiosi/jefPmKS0tTXXr1lW9evXUu3dvrV+/vsx6Tz/9tFq3bq3Y2FideeaZys7O1rBhw9SiRYuSdbZs2SKfz6eHH35YDz30kFq0aKG4uDh1795dX3/9tfx+v+666y41bdpUiYmJuvzyy7V79+5qjWnYsGGqV6+eNm3apL59+6pevXpKSUnRuHHjVFBQUDKek08+WZKUlZUln88nn88X1FsFx8vPz1fv3r3VuHFjffjhh5KkzMxM+Xw+ffzxxxo4cKBOOukktWrVqmQOKvojSffff79q1aqlbdu2ldnW8OHDlZSUpMOHD+uOO+5QYmKiCgsLS26/+eabS+a42J49exQVFaXHH3+81Jhvv/12tWzZUrVr19app56qMWPG6MCBA6W2F+xbJ9XxzTffKCMjQ40aNVJsbKzatGmjv//976XWKX5748UXX9S4ceN06qmnKjY2Vps2bSp5jr/88kv17t1bdevWVZMmTfTggw9KktasWaPzzz9fdevWVevWrfX888+X+9jFe7OGDRtWsv3jn5MtW7ZIkgzD0MyZM9WhQwfFxcXppJNO0sCBA/Xdd99V+XfNysrSeeedp4YNGyohIUHnnHOOZs+eLa7FiZAYgANcf/31hiTj5ptvNtasWWMcOXKkwnUnT55s+Hw+Y/jw4caSJUuMhQsXGmlpaUbdunWNjRs3lqz35JNPGpKMK6+80liyZInxr3/9y2jdurWRmppqpKamlqy3efNmQ5KRmppq9O/f31iyZInxz3/+02jcuLHRunVrY8iQIcbw4cONN954w/jHP/5h1KtXz+jfv3+1xjR06FCjdu3aRps2bYxHHnnEeOutt4z77rvP8Pl8RlZWlmEYhnH48GFj2bJlhiRjxIgRxgcffGB88MEHxqZNmyqck3fffdeQZLz00kuGYRjGtm3bjHbt2hmnn3668e2335asN3HixJK/6/jx442cnBxj8eLFxuHDh0u2U/zn1VdfNRISEow2bdoYhmEYu3btMmJjY4177rmn1Lb37NljxMXFGXfccYdhGEbJ2FevXl2yzhlnnGHExcUZ6enpJcvmzZtnSDI+//xzwzAM48CBA0aHDh2M5ORk47HHHjPeeustY8aMGUZiYqJx0UUXGUVFRSX3TU1NNYYOHVrhfBy/Xt++fQ2/31/mz5o1awxJxpw5c0rW37hxo5GYmGi0a9fOeOGFF4zly5cb48aNM6KioozMzMwy833qq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5LHXrJkidq2basOHTqUmsfevXuX+RRGKM4//3ytXbu2zJ8XXnih1HqHDx/W22+/rcsvv1zx8fGlxtC3b18dPnxYa9asCWoefT6f+vbtW/JzrVq19Jvf/EZNmjQpdXxJw4YN1ahRo2o/90uWLJHP59O1115barynnHKKzj777Crn7J133lHPnj2VmJio6OhoxcTE6L777tOePXvKfXsQKA8Hg8JROnXqpE6dOkkKHFw3fvx4TZs2TVOnTtXUqVO1a9cuSdLvfve7cu9fHAp79uyRJDVu3LjMOo0bN9bmzZvLLD/xl3Lt2rUrXX748GFJCnpMxeLj41WnTp1Sy2JjY0seryYWL16sQ4cO6aabblJsbGyF6zVp0qTC20aOHKlly5bp9ddfV4cOHUrd1rFjR3Xr1k1///vfdc0112jJkiXasmWLnnzyyVLr9ezZU/fff78OHDigt956SxdddJGSkpJ07rnn6q233tJpp52mzZs3l/okxa5du7Rp0ybFxMSUO67i2AxVYmJiyWuqMnv27NHRo0f1+OOPlzpupLIxVDSP5T3HtWvXLjf8ateuXe3nfteuXTIMo9zXuSSddtppFd73ww8/VK9evdS9e3c9/fTTatasmWrXrq3Fixdr8uTJOnToULXGBO8hNOBYMTExmjhxoqZNm6bPPvtMkpScnCxJevnll0v9S/tESUlJko5FwPF27twZ1nEGOyYrTJs2TfPmzVOfPn20aNEi9erVq9z1ig/wPFFmZqaeeeYZzZkzp8L73nLLLbrqqqv08ccf64knnlDr1q2Vnp5eap2LL75Y9957r1auXKm3335bEydOLFm+fPlytWzZsuTnYsnJyYqLi9Ozzz5b7naL59ksJ510kqKjozVkyBCNGjWq3HWKx12sonm0SnJysnw+n957771yw7Ky2Jw
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"Pp = [0.0,0.0]\n",
"Pk = [1.0,0.0]\n",
"Tp = [4.0,4.0]\n",
"Tk = [4.0,-4.0]\n",
"\n",
"lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
"lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Segment krzywej Hermite'a\")\n",
"\n",
"\n",
"def X(t):\n",
" return Pp[0]*hermite_basis_function_2D[0](t) + Pk[0]*hermite_basis_function_2D[1](t) + Tp[0]*hermite_basis_function_2D[2](t) + Tk[0]*hermite_basis_function_2D[3](t)\n",
"\n",
"def Y(t):\n",
" return Pp[1]*hermite_basis_function_2D[0](t) + Pk[1]*hermite_basis_function_2D[1](t) + Tp[1]*hermite_basis_function_2D[2](t) + Tk[1]*hermite_basis_function_2D[3](t)\n",
"\n",
"\n",
"extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
"borderXp = min(extr[0][0],Pp[0]+Tp[0],Pk[0]+Tk[0])-0.1\n",
"borderXk = max(extr[0][1],Pp[0]+Tp[0],Pk[0]+Tk[0])+0.1\n",
"\n",
"borderYp = min(extr[1][0],Pp[1]+Tp[1],Pk[1]+Tk[1])-0.1\n",
"borderYk = max(extr[1][1],Pp[1]+Tp[1],Pk[1]+Tk[1])+0.1\n",
"\n",
"\n",
"plt.xlim(borderXp, borderXk)\n",
"plt.ylim(borderYp, borderYk)\n",
"\n",
"x = X(t)\n",
"y = Y(t)\n",
"\n",
"ax.set_aspect('equal')\n",
"\n",
"ax.plot(x,y, color='red')\n",
"\n",
"ax.plot(Pp[0], Pp[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(Pk[0], Pk[1], color='blue', marker=\".\", markersize=20)\n",
"\n",
"plt.quiver(Pp[0],Pp[1], Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"plt.quiver(Pk[0],Pk[1], Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
"#eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"leg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "0b4e7777",
"metadata": {},
"source": [
"#### 1.3.2. Przykład 2"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a91edba9",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAANCCAYAAABRawmWAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAABepElEQVR4nO3deZyNdf/H8feZxSwyxDAzokFlK5VU9q0YUdokpURp0Y4WtGC429wtSptKUSJFU5Ibo2yFOzLuNilFoxpEMbKMYb6/P67fTMasZ+Zc5zrnOq/n4+Exc85c58znOzPn7nVf5zrX8RhjjAAAAGCLMKcHAAAAcDNiCwAAwEbEFgAAgI2ILQAAABsRWwAAADYitgAAAGxEbAEAANiI2AIAALARsQUAAGAjYgvwgf/+97+67LLLdOKJJyoqKkoJCQlq27at7rnnHqdH87v9+/dr7NixWrp0abm2X7p0qTwej2bPnm3vYAGiQYMGGjRoULm2u+iii4r92tq1a+XxeDR16lTfDldJ+b/Lo3/38+fP19ixYyt1v4MGDVKXLl0qdR+Ak4gtoJI+/vhjtWvXTtnZ2ZowYYIWLVqkZ599Vu3bt9esWbOcHs/v9u/fr9TU1HLHVqhJS0vTww8/7PQYtjjrrLO0atUqnXXWWQXXzZ8/X6mpqQ5OBTgvwukBgGA3YcIENWzYUAsXLlRExD8PqauuukoTJkxwcDL3279/v2JjY50ewystW7Z0eoQicnNz5fF4Cv39VkRcXJzatGnjo6kA92DPFlBJu3btUnx8fLH/oQoLK/oQmzVrltq2bauqVavquOOOU48ePZSRkVFku1dffVWNGzdWVFSUmjdvrhkzZmjQoEFq0KBBwTZbtmyRx+PRv//9bz3xxBNq0KCBYmJi1KVLF/3www/Kzc3VyJEjVbduXVWvXl2XXXaZduzYUaGZBg0apOOOO06bNm1Sr169dNxxx6l+/fq65557lJOTUzBP7dq1JUmpqanyeDzyeDzletrsaNnZ2erRo4cSEhL0xRdfSJLGjh0rj8ejdevW6YorrtDxxx+vk046qeBnUNI/SRo/frwiIiK0devWIt/rhhtuUK1atXTw4EHdd999ql69uo4cOVLw9TvvvLPgZ5xv165dCgsL06RJkwrNfO+996phw4aqUqWKTjjhBA0dOlT79u0r9P3K+zRiRfz444/q37+/6tSpo6ioKDVr1kwvvPBCoW3yn+p76623dM899+iEE05QVFSUNm3aVPA7/v7779WjRw9VrVpVSUlJevzxxyVJq1evVocOHVS1alU1btxY06ZNK/a+8/dqDho0qOD7H/072bJliyTJGKMXX3xRZ555pmJiYnT88cfriiuu0M8//1zmWlNTU9W6dWvVrFlTcXFxOuusszRlyhQZYyr5UwRsYABUyo033mgkmTvvvNOsXr3aHDp0qMRtH3nkEePxeMwNN9xg5s2bZ95//33Ttm1bU7VqVfPtt98WbDd58mQjyfTp08fMmzfPvP3226Zx48YmOTnZJCcnF2y3efNmI8kkJyeb3r17m3nz5pnp06ebhIQE07hxYzNgwABzww03mP/85z/m5ZdfNscdd5zp3bt3hWYaOHCgqVKlimnWrJl58sknzeLFi83o0aONx+MxqampxhhjDh48aBYsWGAkmcGDB5tVq1aZVatWmU2bNpX4M1myZImRZN577z1jjDFbt241LVq0ME2aNDE//fRTwXZjxowpWOuIESNMenq6+eCDD8zBgwcLvk/+v7lz55q4uDjTrFkzY4wx27dvN1FRUebBBx8s9L137dplYmJizH333WeMMQWzr1y5smCbpk2bmpiYGNO9e/eC62bNmmUkme+++84YY8y+ffvMmWeeaeLj483TTz9tFi9ebJ599llTvXp1c95555m8vLyC2yYnJ5uBAweW+PM4ertevXqZ3NzcIv9Wr15tJJk33nijYPtvv/3WVK9e3bRo0cK8+eabZtGiReaee+4xYWFhZuzYsUV+3ieccIK54oorzNy5c828efPMrl27Cv2On332WZOenm6uv/56I8mMGjXKNG7c2EyZMsUsXLjQXHTRRUaSWbt2bZH7XrJkiTHGmE2bNpkrrrjCSCr0+zl48KAxxpibbrrJREZGmnvuuccsWLDAzJgxwzRt2tQkJCSYbdu2lfrzGTRokJkyZYpJT0836enpZvz48SYmJqbgbxEIJMQWUEk7d+40HTp0MJKMJBMZGWnatWtnHnvsMbN3796C7TIzM01ERIS58847C91+7969JjEx0Vx55ZXGGGOOHDliEhMTTevWrQtt98svv5jIyMhiY+uMM84wR44cKbh+4sSJRpK5+OKLC93H0KFDjSSzZ88er2YyxootSebdd98ttG2vXr1MkyZNCi7/8ccfRpIZM2ZMWT86Y0zh2MrIyDB169Y1HTt2NLt27Sq0XX5sjR49utT727dvnzn33HNNUlKS2bJlS6H569SpY3Jycgque+KJJ0xYWJjZvHlzwW2rVKlixo0bZ4wx5tdffzWSzIgRI0xMTEyhSKhbt27B/Tz22GMmLCzMrFmzptAss2fPNpLM/PnzC67zJrby/6ZK+nd0bPXo0cPUq1ev4Heb74477jDR0dHmzz//NMb88/Pu1KlTke+Z/zueM2dOwXW5ubmmdu3aRpJZt25dwfW7du0y4eHhZvjw4QXXHRtbxhhz++23m+L+f/2qVauMJPPUU08Vun7r1q0mJibG3H///WX+jPIdOXLE5ObmmnHjxplatWoVilsgEPA0IlBJtWrV0ooVK7RmzRo9/vjjuuSSS/TDDz9o1KhRatGihXbu3ClJWrhwoQ4fPqzrrrtOhw8fLvgXHR2tzp07Fzz1snHjRm3btk1XXnlloe9z4oknqn379sXO0KtXr0JPWTZr1kySdOGFFxbaLv/6zMxMr2bK5/F41Lt370LXnX766frll1+8+IkVb+HCherYsaM6deqk9PR01axZs9jt+vTpU+J9HDlyRP369dOGDRs0f/58JScnF3zt7rvv1o4dO/Tee+9JkvLy8vTSSy/pwgsvLHhqNjY2Vm3bttXixYslSenp6apRo4buu+8+HTp0SJ999pkkafHixerWrVvBfc+bN0+nnXaazjzzzEI/xx49ehR5dZ43OnTooDVr1hT59+abbxba7uDBg/rkk0902WWXKTY2ttAMvXr10sGDB7V69epy/Rw9Ho969epVcDkiIkInn3yykpKSCh1vVrNmTdWpU6fCv/t58+bJ4/Ho2muvLTRvYmKizjjjjDJ/Zp9++qm6deum6tWrKzw8XJGRkRo9erR27dpV7FPlgJM4QB7wkbPPPltnn322JOuA4xEjRuiZZ57RhAkTNGHCBG3fvl2SdM455xR7+/xY2rVrlyQpISGhyDYJCQnavHlzkeuPDZMqVaqUev3Bgwclqdwz5YuNjVV0dHSh66KiogrurzI++OADHThwQLfeequioqJK3C4pKanErw0ZMkQLFizQxx9/rDPPPLPQ11q2bKmOHTvqhRde0DXXXKN58+Zpy5Ytmjx5cqHtunXrpvHjx2vfvn1avHixzjvvPNWqVUutWrXS4sWL1ahRI23evLnQK+y2b9+uTZs2KTIysti58oPbW9WrVy/4myrNrl27dPjwYU2aNKnQcWSlzVDSz7G433GVKlWKjd8qVapU+He/fft2GWOK/TuXpEaNGpV42y+++EIpKSnq0qWLXn31VdWrV09VqlTRBx98oEceeUQHDhyo0EyAXYgtwAaRkZEaM2aMnnnmGX3zzTeSpPj4eEnS7NmzC+1xOVatWrUk/RNCR9u2bZtP5yzvTP7wzDPPaNasWerZs6fS0tKUkpJS7Hb5B70fa+zYsXrttdf0xhtvlHjbu+66S3379tW6dev0/PPPq3HjxurevXuhbc4//3w9/PDDWr58uT755BONGTOm4PpFixapYcOGBZfzxcfHKyYmRq+//nqx3zf/52yX448/XuHh4RowYIBuv/32YrfJnztfST9Hf4mPj5fH49GKFSuKjevSgvudd95RZGSk5s2bVygMP/jgAztGBSq
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"Pp = [1.0,0.5]\n",
"Pk = [0.0,-0.5]\n",
"Tp = [1.0,1.0]\n",
"Tk = [1.0,-1.0]\n",
"\n",
"lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
"lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Segment krzywej Hermite'a\")\n",
"\n",
"\n",
"def X(t):\n",
" return Pp[0]*hermite_basis_function_2D[0](t) + Pk[0]*hermite_basis_function_2D[1](t) + Tp[0]*hermite_basis_function_2D[2](t) + Tk[0]*hermite_basis_function_2D[3](t)\n",
"\n",
"def Y(t):\n",
" return Pp[1]*hermite_basis_function_2D[0](t) + Pk[1]*hermite_basis_function_2D[1](t) + Tp[1]*hermite_basis_function_2D[2](t) + Tk[1]*hermite_basis_function_2D[3](t)\n",
"\n",
"\n",
"extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
"borderXp = min(extr[0][0],Pp[0]+Tp[0],Pk[0]+Tk[0])-0.1\n",
"borderXk = max(extr[0][1],Pp[0]+Tp[0],Pk[0]+Tk[0])+0.1\n",
"\n",
"borderYp = min(extr[1][0],Pp[1]+Tp[1],Pk[1]+Tk[1])-0.1\n",
"borderYk = max(extr[1][1],Pp[1]+Tp[1],Pk[1]+Tk[1])+0.1\n",
"\n",
"\n",
"plt.xlim(borderXp, borderXk)\n",
"plt.ylim(borderYp, borderYk)\n",
"\n",
"x = X(t)\n",
"y = Y(t)\n",
"\n",
"ax.set_aspect('equal')\n",
"\n",
"ax.plot(x,y, color='red')\n",
"\n",
"ax.plot(Pp[0], Pp[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(Pk[0], Pk[1], color='blue', marker=\".\", markersize=20)\n",
"\n",
"plt.quiver(Pp[0],Pp[1], Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"plt.quiver(Pk[0],Pk[1], Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
"#eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"leg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "b606bf77",
"metadata": {},
"source": [
"#### 1.3.3. Wersja interaktywna"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "cfd6c277",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7bc108357870438d88015b015bcc558b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(FloatSlider(value=0.0, description='PpX', layout=Layout(grid_area='widget001'), …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54144e7d46cf4d5ea3103f2ff44a7525",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"\n",
"def draw_Hermite_segment(PpX,PpY,PkX,PkY,TpX,TpY,TkX,TkY):\n",
" t = np.arange(0.0, 1.01, 0.01)\n",
" \n",
" lenTp = math.sqrt(TpX**2+TpY**2)/2.54\n",
" lenTk = math.sqrt(TkX**2+TkY**2)/2.54 \n",
"\n",
" fig, ax = plt.subplots()\n",
" #ustawienie rozmiaru obrazka na 10x10 cali\n",
" fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
" plt.title(\"Segment krzywej Hermite'a\")\n",
"\n",
"\n",
" def X(t):\n",
" return PpX*hermite_basis_function_2D[0](t) + PkX*hermite_basis_function_2D[1](t) + TpX*hermite_basis_function_2D[2](t) + TkX*hermite_basis_function_2D[3](t)\n",
"\n",
" def Y(t):\n",
" return PpY*hermite_basis_function_2D[0](t) + PkY*hermite_basis_function_2D[1](t) + TpY*hermite_basis_function_2D[2](t) + TkY*hermite_basis_function_2D[3](t)\n",
"\n",
"\n",
" extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
" borderXp = min(extr[0][0],PpX+TpX,PkX+TkX)-0.1\n",
" borderXk = max(extr[0][1],PpX+TpX,PkX+TkX)+0.1\n",
"\n",
" borderYp = min(extr[1][0],PpY+TpY,PkY+TkY)-0.1\n",
" borderYk = max(extr[1][1],PpY+TpY,PkY+TkY)+0.1\n",
"\n",
"\n",
" plt.xlim(borderXp, borderXk)\n",
" plt.ylim(borderYp, borderYk)\n",
"\n",
" x = X(t)\n",
" y = Y(t)\n",
"\n",
" ax.set_aspect('equal')\n",
"\n",
" ax.plot(x,y, color='red')\n",
"\n",
" ax.plot(PpX, PpY, color='blue', marker=\".\", markersize=20)\n",
" ax.plot(PkX, PkY, color='blue', marker=\".\", markersize=20)\n",
"\n",
" plt.quiver(PpX,PpY, TpX , TpY,color='green', angles='xy', scale_units='xy', scale=1)\n",
" plt.quiver(PkX,PkY, TkX , TkY,color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
" #eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
" #leg.get_frame().set_alpha(0.5)\n",
" plt.grid();\n",
"\n",
" plt.show()\n",
"\n",
"Pp1 = [0.0,0.0]\n",
"Pk1 = [1.0,0.0]\n",
"Tp1 = [1.0,1.0]\n",
"Tk1 = [1.0,-1.0]\n",
" \n",
"#draw_Hermite_segment(Pp1[0],Pp1[1],Pk1[0],Pk1[1],Tp1[0],Tp1[1],Tk1[0],Tk1[1])\n",
"grid = widgets.GridspecLayout(4, 2)\n",
"grid[0, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Pp1[0],description='PpX')\n",
"grid[0, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Pp1[1],description='PpY')\n",
"grid[1, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Pk1[0],description='PkX')\n",
"grid[1, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Pk1[1],description='PkY')\n",
"grid[2, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Tp1[0],description='TpX')\n",
"grid[2, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Tp1[1],description='TpY')\n",
"grid[3, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Tk1[0],description='TkX')\n",
"grid[3, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=Tk1[1],description='TkY')\n",
"\n",
"k1 = widgets.VBox([grid[0,0],grid[1,0],grid[2,0],grid[3,0]])\n",
"k2 = widgets.VBox([grid[0,1],grid[1,1],grid[2,1],grid[3,1]])\n",
"ui = widgets.HBox([k1,k2])\n",
"\n",
"out = widgets.interactive_output(draw_Hermite_segment, {'PpX': grid[0,0], 'PpY': grid[0,1], \n",
" 'PkX': grid[1,0], 'PkY': grid[1,1],\n",
" 'TpX': grid[2,0], 'TpY': grid[2,1], \n",
" 'TkX': grid[3,0], 'TkY': grid[3,1]\n",
" })\n",
"\n",
"display(ui, out)\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "5968b7a3",
"metadata": {},
"source": [
"## 2. Krzywe Beziera stopnia 3\n",
"===================================="
]
},
{
"cell_type": "markdown",
"id": "d982705f",
"metadata": {},
"source": [
"### 2.1. Macierz funkcji bazowych"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "90b8487d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[-1.0, 3.0, -3.0, 1.0],\n",
" [3.0, -6.0, 3.0, 0.0],\n",
" [-3.0, 3.0, 0.0, 0.0],\n",
" [1.0, 0.0, 0.0, 0.0]]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bezier_basis_matrix_2D = [\n",
" [-1.0,3.0,-3.0,1.0],\n",
" [3.0,-6.0,3.0,0.0],\n",
" [-3.0,3.0,.0,0.0],\n",
" [1.0,0.0,0.0,0.0]\n",
"]\n",
"bezier_basis_matrix_2D"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f0f7435c",
"metadata": {},
"outputs": [],
"source": [
"bezier_basis_function_2D = []\n",
"bezier_basis_function_2D.append(\n",
" lambda t: bezier_basis_matrix_2D[0][0]*t**3 + bezier_basis_matrix_2D[0][1]*t**2 + bezier_basis_matrix_2D[0][2]*t + bezier_basis_matrix_2D[0][3],\n",
") \n",
"bezier_basis_function_2D.append(\n",
"lambda t: bezier_basis_matrix_2D[1][0]*t**3 + bezier_basis_matrix_2D[1][1]*t**2 + bezier_basis_matrix_2D[1][2]*t + bezier_basis_matrix_2D[1][3]\n",
")\n",
"bezier_basis_function_2D.append(\n",
" lambda t: bezier_basis_matrix_2D[2][0]*t**3 + bezier_basis_matrix_2D[2][1]*t**2 + bezier_basis_matrix_2D[2][2]*t + bezier_basis_matrix_2D[2][3]\n",
")\n",
"bezier_basis_function_2D.append(\n",
"lambda t: bezier_basis_matrix_2D[3][0]*t**3 + bezier_basis_matrix_2D[3][1]*t**2 + bezier_basis_matrix_2D[3][2]*t + bezier_basis_matrix_2D[3][3]\n",
")\n"
]
},
{
"cell_type": "markdown",
"id": "7cb6a787",
"metadata": {},
"source": [
"### 2.2. Wykresy funkcji bazowych"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "041f6aee",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzoAAANCCAYAAACuwLkYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3hUZfrG8e/MJJn0TiAEQu9I74r0DiIWVOxixdVVV9e2umtZ3VV/6qqrrooggl1AmnSlS0eQjvRAKOk9k5nz+2NINNISSHJmJvfnuubCnJyZc8/MSZwn73ue12IYhoGIiIiIiIgPsZodQEREREREpKKp0BEREREREZ+jQkdERERERHyOCh0REREREfE5KnRERERERMTnqNARERERERGfo0JHRERERER8jgodERERERHxOSp0RERERETE56jQERFTT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Hem13PPnj3cfvvtNGnShODgYBISEhgxYgRbtmwp02txJsXPv7oWlCLipt8AIuIRnE5nqQ+hcOEfUu68806GDRvGZ599xqFDh3jssce46aabSqY9/ZFhGDz22GO89dZbfPTRRyUfCIuKihgyZAjLli3joYceom/fvhQVFfHTTz9x8OBBevToccbHy83NpVevXhw+fJinnnqKNm3asHXrVp599lm2bNnCwoULsVgs53wOycnJXH/99TzxxBM8//zzzJ49mxdffJG0tDTeeeedkv3279/PPffcQ2JiIgA//fQTDzzwAElJSTz77LMADBs2jFWrVpV6/FWrVvHII4/QqlWrktfgyiuvZNGiRTz55JP07NmTzZs38/e//51Vq1axatUq7HY7/fv357XXXmPNmjV0794dgIULFxIUFMSCBQt47LHHAFi0aBGGYdC/f/8Ke02K35Pif/fs2cNjjz1GVFQUw4YNK/XadenSBavVyrPPPkujRo1YtWoVL774Ivv372fChAkAPPPMM9x7772lHv+///0vkydPpmXLlmfNsG3bNnr06EFiYiL/93//R61atZg3bx4PPvggJ0+eLFUoAzz55JN0796d999/H6vVSlxcHCdOnADg73//O7Vq1SI7O5tp06bRu3dvFi1adM7pZvv372fYsGH07NmTjz/+mMjISJKSkpg7dy6FhYXEx8czd+5cBg8ezNixY7nzzjuB3z78L1myhAEDBtCmTRvGjx+P3W7n3XffZcSIEXz++edcd911pY43duxYBgwYUPLz9Le//Y3evXuzefNmIiMjS73uN954I3/5y1/4+9//zrRp03jyySepXbs2t9xyy1mfz5EjR4iJieFf//oXNWrUIDU1lU8++YSuXbuyceNGmjVrdtb7/l5RUREOh4MdO3bw0EMP0bRpU6666qoy3VdEfJQhImKiCRMmGMAZbw6HwzAMwwCMv//976fdt169esatt9562mONGzeu1H6vvPKKARhHjx4tdd9hw4YZubm5xtVXX21EREQYCxcuLHW/SZMmGYDx4YcfnvM5/DHHyy+/bFitVmPt2rWl9vvmm28MwJgzZ845H69Xr14GYHz33Xeltt91112G1Wo1Dhw4cMb7OZ1Ow+FwGM8//7wRExNjuFyuM+63Y8cOI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XLGds4nTpygdu3aWK3l+1V57NgxNm/ejL+/f6lbWFgYhmFw8uTJ8z5GzZo1T9tWq1YtwF2gAaxZs4aBAwcC8OGHH7JixQrWrl3L008/fcbnm5WVxdChQ3E4HHz//fcl17cUP6afn1/J9KZiFouFWrVqlRwToH///vz000/k5OSwcOFC+vbtS0xMDB07dmThwoXs27ePffv2lSp0KuI1sVqtJedGly5dGDVqFHPmzMHPz49HHnmk1LF
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Funkcje bazowe Beziera stopnia 3\")\n",
"\n",
"for n in range(4):\n",
" ax.plot(t,bezier_basis_function_2D[n](t) , label=\"b_\"+str(n)+\"(t)\")\n",
"\n",
"leg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"leg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "8a0079a0",
"metadata": {},
"outputs": [],
"source": [
"def find_ext(x,y, lp, lk):\n",
" t = np.arange(lp, lk, 0.001)\n",
" xmin = xmax = x(lp)\n",
" ymin = ymax = y(lp)\n",
" for p in t:\n",
" if x(p) < xmin:\n",
" xmin = x(p)\n",
" else:\n",
" if x(p) > xmax:\n",
" xmax = x(p)\n",
" if y(p) < ymin:\n",
" ymin = y(p)\n",
" else:\n",
" if y(p) > ymax:\n",
" ymax = y(p)\n",
" return [[xmin,xmax],[ymin,ymax]]"
]
},
{
"cell_type": "markdown",
"id": "0356ad14",
"metadata": {},
"source": [
"### 2.3. Przykłady\n",
"\n",
"#### 2.3.1. Przykład 1"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "49b5119f",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAANCCAYAAADPy7GCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAABFKElEQVR4nO3de1xUdeI+8GeQYbgJKiiKIl7yul5iLRUVRU3xrqXdbE2/tv2qNc1bq+WmUmuWWeZqa7WatpWbmpdaLRVLUFNLTdvKW14xBRNJQFAc4fP74zQjIwPMwJz78369eAGHM3M+Zw48nHnmnDMWIYQAEZEG+Kk9ACIiBwYSEWkGA4mINIOBRESawUAiIs1gIBGRZjCQiEgzGEhEpBkMJCLSDFME0jfffIN7770XDRs2hM1mQ1RUFOLj4zFlyhS1h6a4goICzJ49G6mpqR7Nn5qaCovFgk8++UTegWlEo0aNMGbMGI/ms1gszo/AwEDccccdmDx5MrKysmQb34oVK2CxWHDmzBnZlqEmf7UHILdNmzZhyJAhSExMxLx581CvXj1kZGRg//79+Pjjj/H666+rPURFFRQUIDk5GQCQmJio7mA0aP369QgLC/No3q5du2L+/PkAgGvXrmH//v2YPXs2duzYgf3798syvoEDB2LPnj2oV6+eLPevNsMH0rx589C4cWNs2bIF/v63Vvehhx7CvHnzVByZ8RUUFCA4OFjtYXglLi7O43lr1KiBzp07O7/v2bMn8vLy8NJLL+H48eNo3ry5z8dXu3Zt1K5d22f3p7VtZPinbJcvX0ZkZKRLGDn4+ZVe/VWrViE+Ph4hISEIDQ1FUlISDh48WGq+f/3rX2jevDlsNhtat26NlStXYsyYMWjUqJFznjNnzsBiseC1117Dq6++ikaNGiEoKAiJiYk4fvw47HY7pk+fjujoaISHh+Pee+/Fr7/+WqkxjRkzBqGhoThx4gQGDBiA0NBQxMTEYMqUKSgsLHSOx/HLnJyc7Hy64clTlJJyc3ORlJSEqKgofPvttwCA2bNnw2Kx4LvvvsOIESNQs2Z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QbN27EmTNn8M4777jMd8899+Cll15Cfn4+tm3bhl69eiEiIgIdOnTAtm3b0KRJE5w+fdr5SiIgPY4nTpwo1es4VPZl+vDwcOfvFAB06dIFrVu3Rnx8PF5//XXMnTvXuQ2nTp2KqVOnerT8Dz/8EM8//zxmzpyJxx57rNwxOO5/xIgRZc6TnZ2NkJAQ5/futtHIkSPx5Zdf4oUXXsDdd9+NsLAwWCwWDBgwANeuXSt3DL5kmkAqyWq1YtasWViwYAF+/PFHAEBkZCQA4JNPPnH5z327iIgIALd+EUrKzMz06Tg9HZMSFixYgFWrVqF///5Yv349+vbt63Y+R1F9u9mzZ2Pp0qVYvnx5mbedMGEC7r//fnz33XdYvHgxmjdvjj59+rjM07t3b7zwwgvYsWMHvvzyS8yaNcs5fevWrWjcuLHze4fIyEgEBQXhvffec7tcx+PsC+3atQMAfP/99y73/dxzz+G+++5ze5sWLVo4v05JScHYsWMxZswYl1Ati+P+Fy1a5PKKX0m3//O8fRvl5ORg48aNmDVrFqZPn+6cXlhYiOzs7ArH4EuGD6SMjAy3/xEcu6HR0dEAgKSkJPj7++PkyZPlPu1o0aIF6tati9WrV2Py5MnO6enp6di9e7fz/nzB0zF5w7F34+1/vcDAQKxbtw5/+tOfMGTIEKxatQpDhw716LbLli1DcnIyXnzxxXJfwXIcvDplyhSkpaVhwYIFpf54OnbsiLCwMLz55pvIzMx0BtY999yDV199FatXr0br1q1dtsOgQYPw8ss
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"### %matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"P0 = [0.0,0.0]\n",
"P1 = [0.25,1.0]\n",
"P2 = [0.75,1.0]\n",
"P3 = [1.0,0.0]\n",
"\n",
"Tp= [3.0*(P1[0]-P0[0]),3.0*(P1[1]-P0[1])]\n",
"Tk= [3.0*(P3[0]-P2[0]),3.0*(P3[1]-P2[1])]\n",
"\n",
"lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
"lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Segment krzywej Beziera\")\n",
"\n",
"\n",
"def X(t):\n",
" return P0[0]*bezier_basis_function_2D[0](t) + P1[0]*bezier_basis_function_2D[1](t) + P2[0]*bezier_basis_function_2D[2](t) + P3[0]*bezier_basis_function_2D[3](t)\n",
"\n",
"def Y(t):\n",
" return P0[1]*bezier_basis_function_2D[0](t) + P1[1]*bezier_basis_function_2D[1](t) + P2[1]*bezier_basis_function_2D[2](t) + P3[1]*bezier_basis_function_2D[3](t)\n",
"\n",
"\n",
"extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
"borderXp = min(extr[0][0],P0[0]+Tp[0],P3[0]+Tk[0],P0[0],P1[0],P2[0],P3[0])-0.1\n",
"borderXk = max(extr[0][1],P0[0]+Tp[0],P3[0]+Tk[0],P0[0],P1[0],P2[0],P3[0])+0.1\n",
"\n",
"borderYp = min(extr[1][0],P0[1]+Tp[1],P3[1]+Tk[1],P0[1],P1[1],P2[1],P3[1])-0.1\n",
"borderYk = max(extr[1][1],P0[1]+Tp[1],P3[1]+Tk[1],P0[1],P1[1],P2[1],P3[1])+0.1\n",
"\n",
"\n",
"plt.xlim(borderXp, borderXk)\n",
"plt.ylim(borderYp, borderYk)\n",
"\n",
"x = X(t)\n",
"y = Y(t)\n",
"\n",
"ax.set_aspect('equal')\n",
"\n",
"ax.plot(x,y, color='red')\n",
"\n",
"ax.plot(P0[0], P0[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P1[0], P1[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P2[0], P2[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P3[0], P3[1], color='blue', marker=\".\", markersize=20)\n",
"\n",
"\n",
"\n",
"plt.quiver(P0[0],P0[1], Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"plt.quiver(P3[0],P3[1], Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
"#eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"#eg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "d4c94e72",
"metadata": {},
"source": [
"#### 2.3.2. Przykład 2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "1a029ca7",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ8AAANCCAYAAAB4dkmlAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAABXsUlEQVR4nO3de1xUdf4/8NcAwwAqXlAQFRErTc2KsJL1fgESM2t1a9cuulbf/OZq5rqm1qbWr+xiZVlplpctv25WqGtpJpqgpW6S2M1LZSpmoOEFFAQG+fz+OJ3JkZlh5syZOZd5PR8PHjBnzpl5cxhfzrzmzIxFCCFAROSjMK0HICJjYngQkSIMDyJShOFBRIowPIhIEYYHESnC8CAiRRgeRKQIw4OIFDF8ePz3v//Fbbfdhvbt28NmsyEhIQHp6en4+9//rvVoQVdZWYlZs2YhLy/Pq/Xz8vJgsVjwwQcfBHYwnejQoQPGjBnj1XoWi8XxFRUVhcsvvxyTJ09GaWlpwOZbtmwZLBYLDh8+HLDrUFOE1gP4Y926dbjlllvQv39/PPfcc0hMTERxcTEKCgrw7rvv4oUXXtB6xKCqrKzE7NmzAQD9+/fXdhgdWr16NWJjY71at1evXpg7dy4A4Pz58ygoKMCsWbOwdetWFBQUBGS+oUOHYseOHUhMTAzI5avN0OHx3HPPISUlBZ988gkiI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GGxAbG4t58+ahpKTEES6DBw/
"text/plain": [
"<Figure size 1000x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"### %matplotlib inline\n",
"\n",
"t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
"P0 = [0.0,0.0]\n",
"P1 = [0.25,1.0]\n",
"P2 = [1.0,0.0]\n",
"P3 = [0.75,1.0]\n",
"\n",
"Tp= [3.0*(P1[0]-P0[0]),3.0*(P1[1]-P0[1])]\n",
"Tk= [3.0*(P3[0]-P2[0]),3.0*(P3[1]-P2[1])]\n",
"\n",
"lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
"lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
"\n",
"fig, ax = plt.subplots()\n",
"#ustawienie rozmiaru obrazka na 10x10 cali\n",
"fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
"plt.title(\"Segment krzywej Beziera\")\n",
"\n",
"\n",
"def X(t):\n",
" return P0[0]*bezier_basis_function_2D[0](t) + P1[0]*bezier_basis_function_2D[1](t) + P2[0]*bezier_basis_function_2D[2](t) + P3[0]*bezier_basis_function_2D[3](t)\n",
"\n",
"def Y(t):\n",
" return P0[1]*bezier_basis_function_2D[0](t) + P1[1]*bezier_basis_function_2D[1](t) + P2[1]*bezier_basis_function_2D[2](t) + P3[1]*bezier_basis_function_2D[3](t)\n",
"\n",
"\n",
"extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
"borderXp = min(extr[0][0],P0[0]+Tp[0],P3[0]+Tk[0],P0[0],P1[0],P2[0],P3[0])-0.1\n",
"borderXk = max(extr[0][1],P0[0]+Tp[0],P3[0]+Tk[0],P0[0],P1[0],P2[0],P3[0])+0.1\n",
"\n",
"borderYp = min(extr[1][0],P0[1]+Tp[1],P3[1]+Tk[1],P0[1],P1[1],P2[1],P3[1])-0.1\n",
"borderYk = max(extr[1][1],P0[1]+Tp[1],P3[1]+Tk[1],P0[1],P1[1],P2[1],P3[1])+0.1\n",
"\n",
"plt.xlim(borderXp, borderXk)\n",
"plt.ylim(borderYp, borderYk)\n",
"\n",
"x = X(t)\n",
"y = Y(t)\n",
"\n",
"ax.set_aspect('equal')\n",
"\n",
"ax.plot(x,y, color='red')\n",
"\n",
"ax.plot(P0[0], P0[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P1[0], P1[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P2[0], P2[1], color='blue', marker=\".\", markersize=20)\n",
"ax.plot(P3[0], P3[1], color='blue', marker=\".\", markersize=20)\n",
"\n",
"\n",
"\n",
"plt.quiver(P0[0],P0[1], Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"plt.quiver(P3[0],P3[1], Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
"#eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
"#leg.get_frame().set_alpha(0.5)\n",
"plt.grid();\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "1ecf0af3",
"metadata": {},
"source": [
"#### 2.3.3. Wersja interaktywna"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d4210ae6",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ae1e5e758e194d3aa8b88313f8b3d7ed",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(FloatSlider(value=0.0, description='P0X', layout=Layout(grid_area='widget001'), …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8106e842beb4475780a5b2d1627faf12",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"\n",
"def draw_Bezier_segment(P0X,P0Y,P1X,P1Y,P2X,P2Y,P3X,P3Y):\n",
" t = np.arange(0.0, 1.01, 0.01)\n",
" \n",
" ### %matplotlib inline\n",
"\n",
" t = np.arange(0.0, 1.01, 0.01)\n",
"\n",
" Tp= [3.0*(P1X-P0X),3.0*(P1Y-P0Y)]\n",
" Tk= [3.0*(P3X-P2X),3.0*(P3Y-P2Y)]\n",
"\n",
" lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
" lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
"\n",
" fig, ax = plt.subplots()\n",
" #ustawienie rozmiaru obrazka na 10x10 cali\n",
" fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
" plt.title(\"Segment krzywej Beziera\")\n",
"\n",
"\n",
" def X(t):\n",
" return P0X*bezier_basis_function_2D[0](t) + P1X*bezier_basis_function_2D[1](t) + P2X*bezier_basis_function_2D[2](t) + P3X*bezier_basis_function_2D[3](t)\n",
"\n",
" def Y(t):\n",
" return P0Y*bezier_basis_function_2D[0](t) + P1Y*bezier_basis_function_2D[1](t) + P2Y*bezier_basis_function_2D[2](t) + P3Y*bezier_basis_function_2D[3](t)\n",
"\n",
"\n",
" extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
" borderXp = min(extr[0][0],P0X+Tp[0],P3X+Tk[0],P0X,P1X,P2X,P3X)-0.2\n",
" borderXk = max(extr[0][1],P0X+Tp[0],P3X+Tk[0],P0X,P1X,P2X,P3X)+0.2\n",
"\n",
" borderYp = min(extr[1][0],P0Y+Tp[1],P3Y+Tk[1],P0Y,P1Y,P2Y,P3Y)-0.2\n",
" borderYk = max(extr[1][1],P0Y+Tp[1],P3Y+Tk[1],P0Y,P1Y,P2Y,P3Y)+0.2\n",
"\n",
" plt.xlim(borderXp, borderXk)\n",
" plt.ylim(borderYp, borderYk)\n",
"\n",
" x = X(t)\n",
" y = Y(t)\n",
"\n",
" ax.set_aspect('equal')\n",
"\n",
" ax.plot(x,y, color='red')\n",
"\n",
" ax.plot(P0X, P0Y, color='blue', marker=\".\", markersize=20)\n",
" ax.plot(P1X, P1Y, color='blue', marker=\".\", markersize=20)\n",
" ax.plot(P2X, P2Y, color='blue', marker=\".\", markersize=20)\n",
" ax.plot(P3X, P3Y, color='blue', marker=\".\", markersize=20)\n",
"\n",
"\n",
"\n",
" plt.quiver(P0X,P0Y, Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
" plt.quiver(P3X,P3Y, Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
" #eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
" #leg.get_frame().set_alpha(0.5)\n",
" plt.grid();\n",
"\n",
" plt.show()\n",
"\n",
"p0 = [0.0,0.0]\n",
"p1 = [0.25,1.0]\n",
"p2 = [0.75,1.0]\n",
"p3 = [1.0,0.0]\n",
" \n",
"#draw_Hermite_segment(Pp1[0],Pp1[1],Pk1[0],Pk1[1],Tp1[0],Tp1[1],Tk1[0],Tk1[1])\n",
"grid = widgets.GridspecLayout(4, 2)\n",
"grid[0, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p0[0],description='P0X')\n",
"grid[0, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p0[1],description='P0Y')\n",
"grid[1, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p1[0],description='P1X')\n",
"grid[1, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p1[1],description='P1Y')\n",
"grid[2, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p2[0],description='P2X')\n",
"grid[2, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p2[1],description='P2Y')\n",
"grid[3, 0] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p3[0],description='P3X')\n",
"grid[3, 1] = widgets.FloatSlider(min=-5, max=5, step=0.2,value=p3[1],description='P3Y')\n",
"\n",
"k1 = widgets.VBox([grid[0,0],grid[1,0],grid[2,0],grid[3,0]])\n",
"k2 = widgets.VBox([grid[0,1],grid[1,1],grid[2,1],grid[3,1]])\n",
"ui = widgets.HBox([k1,k2])\n",
"\n",
"out = widgets.interactive_output(draw_Bezier_segment, {'P0X': grid[0,0], 'P0Y': grid[0,1], \n",
" 'P1X': grid[1,0], 'P1Y': grid[1,1],\n",
" 'P2X': grid[2,0], 'P2Y': grid[2,1], \n",
" 'P3X': grid[3,0], 'P3Y': grid[3,1]\n",
" })\n",
"\n",
"display(ui, out)\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "31c960d2",
"metadata": {},
"source": [
"### 2.4. Krzywe Beziera dowolnego stopnia"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "c0e13970",
"metadata": {},
"outputs": [],
"source": [
"import scipy.special\n",
"def bernstein(n,i,t):\n",
" return scipy.special.binom(n,i)*t**i*(1-t)**(n-i)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "ea3578d6",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cbcc840f1bd9484382925bfc740223af",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GridspecLayout(children=(FloatText(value=0.0, description='pX', layout=Layout(grid_area='widget001', width='20…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c56363fef08f414a8db211f01116d59e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e351bb5029214249abd6e2d4218c8d07",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Checkbox(value=False, description='Show convex hull', indent=False), Output()), _dom_cla…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"from IPython.display import clear_output\n",
"from scipy.spatial import ConvexHull, convex_hull_plot_2d\n",
"from ipywidgets import Button, Layout\n",
"from ipywidgets import interact\n",
"\n",
"out = widgets.Output()\n",
"\n",
"def onclick(event):\n",
" print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %\n",
" ('double' if event.dblclick else 'single', event.button,\n",
" event.x, event.y, event.xdata, event.ydata))\n",
"\n",
"\n",
"def draw_Bezier_segment_n(control_points,out, hull = False):\n",
" t = np.arange(0.0, 1.01, 0.01)\n",
" \n",
" ### %matplotlib inline\n",
"\n",
" t = np.arange(0.0, 1.01, 0.01)\n",
" \n",
" n = len(control_points)-1\n",
"\n",
" Tp= [3.0*(control_points[1][0]-control_points[0][0]),3.0*(control_points[1][1]-control_points[0][1])]\n",
" Tk= [3.0*(control_points[n][0]-control_points[n-1][0]),3.0*(control_points[n][1]-control_points[n-1][1])]\n",
"\n",
" lenTp = math.sqrt(Tp[0]**2+Tp[1]**2)/2.54\n",
" lenTk = math.sqrt(Tk[0]**2+Tk[1]**2)/2.54 \n",
"\n",
" \n",
" with out:\n",
" fig, ax = plt.subplots()\n",
" \n",
" cid = fig.canvas.mpl_connect('button_press_event', onclick)\n",
"\n",
" #ustawienie rozmiaru obrazka na 10x10 cali\n",
" fig.set_size_inches(25.4/2.54, 25.4/2.54, forward=True)\n",
" plt.title(\"Segment krzywej Beziera stopnia \"+str(n))\n",
"\n",
"\n",
" def X(t):\n",
" res = 0\n",
" for i in range(n+1):\n",
" res += control_points[i][0]*bernstein(n,i,t)\n",
" return res\n",
" \n",
" \n",
" def Y(t):\n",
" res = 0\n",
" for i in range(n+1):\n",
" res += control_points[i][1]*bernstein(n,i,t)\n",
" return res\n",
" \n",
"\n",
" extr = find_ext(X,Y,0.0,1.01)\n",
"\n",
" \n",
" extr_points = [[control_points[0][0],control_points[0][0]],[control_points[0][1],control_points[0][1]]]\n",
" for i in range(1,n+1):\n",
" if control_points[i][0] < extr_points[0][0]:\n",
" extr_points[0][0] = control_points[i][0]\n",
" else:\n",
" if control_points[i][0] > extr_points[0][1]:\n",
" extr_points[0][1] = control_points[i][0]\n",
" if control_points[i][1] < extr_points[1][0]:\n",
" extr_points[1][0] = control_points[i][1]\n",
" else:\n",
" if control_points[i][1] > extr_points[1][1]:\n",
" extr_points[1][1] = control_points[i][1]\n",
"\n",
" borderXp = min(extr[0][0],control_points[0][0]+Tp[0],control_points[n][0]+Tk[0],extr_points[0][0])-0.2\n",
" borderXk = max(extr[0][1],control_points[0][0]+Tp[0],control_points[n][0]+Tk[0],extr_points[0][1])+0.2\n",
" \n",
" borderYp = min(extr[1][0],control_points[0][1]+Tp[1],control_points[n][1]+Tk[1],extr_points[1][0])-0.2\n",
" borderYk = max(extr[1][1],control_points[0][1]+Tp[1],control_points[n][1]+Tk[1],extr_points[1][1])+0.2\n",
" \n",
" \n",
"\n",
" plt.xlim(borderXp, borderXk)\n",
" plt.ylim(borderYp, borderYk)\n",
"\n",
" x = X(t)\n",
" y = Y(t)\n",
"\n",
" ax.set_aspect('equal')\n",
"\n",
" with out:\n",
" clear_output(True)\n",
" \n",
" ax.plot(x,y, color='red')\n",
"\n",
" for i in range(n+1):\n",
" ax.plot(control_points[i][0], control_points[i][1], color='blue', marker=\".\", markersize=20)\n",
"\n",
"\n",
"\n",
" plt.quiver(control_points[0][0], control_points[0][1], Tp[0] , Tp[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
" plt.quiver(control_points[n][0], control_points[n][1], Tk[0] , Tk[1],color='green', angles='xy', scale_units='xy', scale=1)\n",
"\n",
"\n",
" #eg = ax.legend(loc='upper center', ncol=2, shadow='True')\n",
" #leg.get_frame().set_alpha(0.5)\n",
" plt.grid();\n",
"\n",
" if hull and len(points)>2:\n",
" Hull = ConvexHull(points)\n",
" #print(Hull.vertices.tolist())\n",
" a=[]\n",
" b=[]\n",
" for i in Hull.vertices.tolist():\n",
" #ax.plot(points[i][0], points[i][1], color='orange', marker=\"*\", markersize=8)\n",
" a.append(points[i][0])\n",
" b.append(points[i][1])\n",
" a.append(a[0])\n",
" b.append(b[0])\n",
" #print(a)\n",
" #print(b)\n",
" for i in Hull.vertices.tolist():\n",
" #print(points[Hull.vertices.tolist()[i]])\n",
" #ax.plot(points[i][0], points[i][1], 'r--', color='black')\n",
" ax.plot(a, b, 'r--', color='black')\n",
" for i in Hull.vertices.tolist():\n",
" ax.plot(points[i][0], points[i][1], color='orange', marker=\"*\", markersize=8)\n",
" \n",
" #_ = convex_hull_plot_2d(Hull)\n",
" \n",
" plt.show()\n",
"\n",
"\n",
"points = [[0.0,0.0], [1.0,0.0],[2.0,2.0]]\n",
"\n",
"\n",
"pointX = widgets.FloatText(\n",
" value=0.0,\n",
" description='pX',\n",
" disabled=False,\n",
" layout=Layout(width='200px')\n",
")\n",
"\n",
"pointY = widgets.FloatText(\n",
" value=0.0,\n",
" description='pY',\n",
" disabled=False,\n",
" layout=Layout(width='200px')\n",
")\n",
"\n",
"\n",
"addIdx = widgets.IntText(\n",
" value=0,\n",
" description='Add Idx',\n",
" disabled=False,\n",
" layout=Layout(width='200px')\n",
")\n",
"\n",
"delIdx = widgets.IntText(\n",
" value=0,\n",
" description='Del Idx',\n",
" disabled=False,\n",
" layout=Layout(width='200px')\n",
")\n",
"\n",
"show_hull = widgets.Checkbox(\n",
" value=False,\n",
" description='Show convex hull',\n",
" disabled=False,\n",
" indent=False\n",
")\n",
"\n",
"def hull_fun(val):\n",
" draw_Bezier_segment_n(points,out,val)\n",
"\n",
"def update_plot(b):\n",
" if b.description == 'Add Point':\n",
" points.insert(addIdx.value,[pointX.value,pointY.value])\n",
" if b.description == 'Del Point':\n",
" del points[delIdx.value]\n",
" draw_Bezier_segment_n(points,out,show_hull.value)\n",
" \n",
"add_button = widgets.Button(description='Add Point',layout=Layout(width='200px'),merge=False)\n",
"del_button = widgets.Button(description='Del Point',layout=Layout(width='200px'))\n",
"add_button.on_click(update_plot)\n",
"del_button.on_click(update_plot)\n",
"\n",
"grid = widgets.GridspecLayout(4, 2,width='460px')\n",
"grid[0, 0] = pointX\n",
"grid[1, 0] = pointY\n",
"grid[2, 0] = addIdx\n",
"grid[3, 0] = add_button\n",
"grid[0, 1] = delIdx\n",
"grid[1, 1] = del_button\n",
"\n",
"\n",
"\n",
"display(grid,out)\n",
"interact(hull_fun,val=show_hull)\n",
"draw_Bezier_segment_n(points,out,show_hull.value)\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "dac98b97",
"metadata": {},
"source": [
"## Zadania "
]
},
{
"cell_type": "markdown",
"id": "a2ba0722",
"metadata": {},
"source": [
"\n",
" \\begin{enumerate}\n",
" \\item Do skryptu w punkcie 2.4. dodać możliwość modyfikacji dowolnego punktu kontrolnego (nieobowiązkowe)\n",
" \\item Napisać skrypt demonstrujący łączenie krzywych Beziera 3-go stopnia, z ciągłością parametryczną w punkcie łączenia.\n",
" \\item Napisać skrypt implementujący rysowanie krzywych Beziera 3-go stopnia algorytmem de Casteljau.\n",
" \\end{enumerate}\n",
" Alternatywnie napisać własny program realizujący te zadania.<p></p>\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a635bc7",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.9.13"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}