worm notebook

This commit is contained in:
looooo
2024-12-24 19:31:14 +01:00
parent d7b4df66f2
commit e117b916b7
5 changed files with 1725 additions and 2003 deletions

Binary file not shown.

View File

@@ -152,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 27,
"id": "cfd8026b-5a84-4882-a1de-63580776a579",
"metadata": {},
"outputs": [],
@@ -163,37 +163,37 @@
"\n",
"from pygears.transformation import symbolic_transformation, numeric_transformation\n",
"\n",
"t, x, z, m = sym.symbols([\"t\", \"x\", \"z\", \"m\"], real=True)\n",
"s, alpha, n_t, y = sym.symbols([\"s\", \"alpha\", \"n_t\", \"y\"], real=True, positiv=True)"
"t, x, z, m, r_w = sym.symbols([\"t\", \"x\", \"z\", \"m\", \"r_w\"], real=True)\n",
"s, alpha, n_t, y, phi = sym.symbols([\"s\", \"alpha\", \"n_t\", \"y\", \"phi\"], real=True, positiv=True)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "65bb90d7-0f5b-410e-9a3a-0f9953a4d846",
"execution_count": 9,
"id": "618dd2ae-e8e5-430d-8c8c-8983358334b7",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\cos{\\left(2 \\pi t \\right)} & \\sin{\\left(2 \\pi t \\right)} & 0 & 0\\\\- \\sin{\\left(2 \\pi t \\right)} & \\cos{\\left(2 \\pi t \\right)} & 0 & 0\\\\0 & 0 & 1 & \\pi m n_{t} t\\\\0 & 0 & 0 & 1.0\\end{matrix}\\right]$"
"$\\displaystyle \\left[\\begin{matrix}1 & 0 & 0 & r_{w}\\\\0 & 1 & 0 & 0\\\\0 & 0 & 1 & 0\\\\0.0 & 0.0 & 0.0 & 1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ cos(2*pi*t), sin(2*pi*t), 0, 0],\n",
"[-sin(2*pi*t), cos(2*pi*t), 0, 0],\n",
"[ 0, 0, 1, pi*m*n_t*t],\n",
"[ 0, 0, 0, 1.0]])"
"[ 1, 0, 0, r_w],\n",
"[ 0, 1, 0, 0],\n",
"[ 0, 0, 1, 0],\n",
"[0.0, 0.0, 0.0, 1.0]])"
]
},
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T_spiral = symbolic_transformation(t * 2 * sym.pi, np.array([0, 0, 1]), np.array([0, 0, m * sym.pi * n_t * t ]))\n",
"T_spiral"
"p0 = symbolic_transformation(0,np.array([0, 0, 1]), [r_w, 0, 0, 1])\n",
"p0"
]
},
{
@@ -205,14 +205,14 @@
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}0\\\\s \\cos{\\left(\\alpha \\right)}\\\\s \\sin{\\left(\\alpha \\right)}\\\\1\\end{matrix}\\right]$"
"$\\displaystyle \\left[\\begin{matrix}r_{w} + s \\cos{\\left(\\alpha \\right)}\\\\0\\\\- s \\sin{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ 0],\n",
"[s*cos(alpha)],\n",
"[s*sin(alpha)],\n",
"[ 1]])"
"[r_w + s*cos(alpha)],\n",
"[ 0],\n",
"[ -s*sin(alpha)],\n",
"[ 1.0]])"
]
},
"execution_count": 11,
@@ -221,30 +221,59 @@
}
],
"source": [
"l = sym.Matrix([0, s * sym.cos(alpha), s * sym.sin(alpha), 1])\n",
"l = p0 @ sym.Matrix([s * sym.cos(alpha), 0, -s * sym.sin(alpha), 1])\n",
"l"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 19,
"id": "65bb90d7-0f5b-410e-9a3a-0f9953a4d846",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\cos{\\left(\\phi \\right)} & \\sin{\\left(\\phi \\right)} & 0 & 0\\\\- \\sin{\\left(\\phi \\right)} & \\cos{\\left(\\phi \\right)} & 0 & 0\\\\0 & 0 & 1 & m n_{t} \\phi\\\\0.0 & 0.0 & 0.0 & 1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ cos(phi), sin(phi), 0, 0],\n",
"[-sin(phi), cos(phi), 0, 0],\n",
"[ 0, 0, 1, m*n_t*phi],\n",
"[ 0.0, 0.0, 0.0, 1.0]])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T_spiral = symbolic_transformation(phi, np.array([0, 0, 1]), np.array([0, 0, m * phi * n_t]))\n",
"T_spiral"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "da3c8575-99ad-4258-8734-c165ea65b014",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}s \\sin{\\left(2 \\pi t \\right)} \\cos{\\left(\\alpha \\right)}\\\\s \\cos{\\left(\\alpha \\right)} \\cos{\\left(2 \\pi t \\right)}\\\\\\pi m n_{t} t + s \\sin{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
"$\\displaystyle \\left[\\begin{matrix}\\left(r_{w} + s \\cos{\\left(\\alpha \\right)}\\right) \\cos{\\left(\\phi \\right)}\\\\- \\left(r_{w} + s \\cos{\\left(\\alpha \\right)}\\right) \\sin{\\left(\\phi \\right)}\\\\1.0 m n_{t} \\phi - s \\sin{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ s*sin(2*pi*t)*cos(alpha)],\n",
"[ s*cos(alpha)*cos(2*pi*t)],\n",
"[pi*m*n_t*t + s*sin(alpha)],\n",
"[ 1.0]])"
"[ (r_w + s*cos(alpha))*cos(phi)],\n",
"[-(r_w + s*cos(alpha))*sin(phi)],\n",
"[ 1.0*m*n_t*phi - s*sin(alpha)],\n",
"[ 1.0]])"
]
},
"execution_count": 12,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
@@ -256,103 +285,105 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 21,
"id": "e47eb83b-6e89-4246-a82a-bd5629aedc2a",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\frac{\\operatorname{asin}{\\left(\\frac{x}{s \\cos{\\left(\\alpha \\right)}} \\right)}}{2 \\pi}$"
"$\\displaystyle \\operatorname{acos}{\\left(\\frac{x}{r_{w} + s \\cos{\\left(\\alpha \\right)}} \\right)}$"
],
"text/plain": [
"asin(x/(s*cos(alpha)))/(2*pi)"
"acos(x/(r_w + s*cos(alpha)))"
]
},
"execution_count": 13,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x_cross_section = sym.simplify(sym.solve(spiral[0] - x, t)[1])\n",
"x_cross_section # parameter s"
"x_cross_section = sym.simplify(sym.solve(spiral[0] - x, phi)[1])\n",
"x_cross_section"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 22,
"id": "c2954b39-eea0-4e27-987f-07a5d0dedaad",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}x\\\\s \\sqrt{1 - \\frac{x^{2}}{s^{2} \\cos^{2}{\\left(\\alpha \\right)}}} \\cos{\\left(\\alpha \\right)}\\\\\\frac{m n_{t} \\operatorname{asin}{\\left(\\frac{x}{s \\cos{\\left(\\alpha \\right)}} \\right)}}{2} + s \\sin{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
"$\\displaystyle \\left[\\begin{matrix}x\\\\- \\sqrt{- \\frac{x^{2} - \\left(r_{w} + s \\cos{\\left(\\alpha \\right)}\\right)^{2}}{\\left(r_{w} + s \\cos{\\left(\\alpha \\right)}\\right)^{2}}} \\left(r_{w} + s \\cos{\\left(\\alpha \\right)}\\right)\\\\1.0 m n_{t} \\operatorname{acos}{\\left(\\frac{x}{r_{w} + s \\cos{\\left(\\alpha \\right)}} \\right)} - s \\sin{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ x],\n",
"[s*sqrt(1 - x**2/(s**2*cos(alpha)**2))*cos(alpha)],\n",
"[ m*n_t*asin(x/(s*cos(alpha)))/2 + s*sin(alpha)],\n",
"[ 1.0]])"
"[ x],\n",
"[-sqrt(-(x**2 - (r_w + s*cos(alpha))**2)/(r_w + s*cos(alpha))**2)*(r_w + s*cos(alpha))],\n",
"[ 1.0*m*n_t*acos(x/(r_w + s*cos(alpha))) - s*sin(alpha)],\n",
"[ 1.0]])"
]
},
"execution_count": 14,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spiral_x = sym.simplify(spiral.subs({t: x_cross_section}))\n",
"spiral_x = sym.simplify(spiral.subs({phi: x_cross_section}))\n",
"spiral_x"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 29,
"id": "268c6302-4e7d-45e0-be28-1b64cf8b766e",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\frac{\\sqrt{x^{2} + y^{2}}}{\\cos{\\left(\\alpha \\right)}}$"
"$\\displaystyle \\frac{- r_{w} + \\sqrt{x^{2} + y^{2}}}{\\cos{\\left(\\alpha \\right)}}$"
],
"text/plain": [
"sqrt(x**2 + y**2)/cos(alpha)"
"(-r_w + sqrt(x**2 + y**2))/cos(alpha)"
]
},
"execution_count": 15,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_cross_section = sym.simplify(sym.solve(spiral_x[1]- y, s)[0])\n",
"y_cross_section\n",
"y_cross_section = (sym.sqrt(x**2 + y**2) - r_w) / sym.cos(alpha)\n",
"y_cross_section"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 30,
"id": "7284bd6a-b47b-483c-8e9f-79fcaecce5e3",
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}x\\\\y\\\\\\frac{m n_{t} \\operatorname{asin}{\\left(\\frac{x}{r{\\left(x,y \\right)}} \\right)}}{2} + r{\\left(x,y \\right)} \\tan{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
"$\\displaystyle \\left[\\begin{matrix}x\\\\- y\\\\1.0 m n_{t} \\operatorname{acos}{\\left(\\frac{x}{r{\\left(x,y \\right)}} \\right)} + 1.0 r_{w} \\tan{\\left(\\alpha \\right)} - 1.0 r{\\left(x,y \\right)} \\tan{\\left(\\alpha \\right)}\\\\1.0\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ x],\n",
"[ y],\n",
"[m*n_t*asin(x/r(x, y))/2 + r(x, y)*tan(alpha)],\n",
"[ 1.0]])"
"[ x],\n",
"[ -y],\n",
"[1.0*m*n_t*acos(x/r(x, y)) + 1.0*r_w*tan(alpha) - 1.0*r(x, y)*tan(alpha)],\n",
"[ 1.0]])"
]
},
"execution_count": 16,
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
@@ -366,7 +397,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 31,
"id": "e7b9f7cc-59f0-4dc6-922c-c94a753c0fd5",
"metadata": {},
"outputs": [
@@ -379,7 +410,7 @@
"z(x, y)"
]
},
"execution_count": 17,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
@@ -391,7 +422,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 32,
"id": "080e1845-8ff4-493e-aa28-5b677bfa3cb4",
"metadata": {},
"outputs": [
@@ -404,7 +435,7 @@
"(y - y_p + z(x, y)*Derivative(z(x, y), y))/sqrt((y - y_p)**2 + z(x, y)**2)"
]
},
"execution_count": 18,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
@@ -458,9 +489,9 @@
"def compute_involute(module=1, teeth=15, height=5, worm_pitch_diameter=10, num_threads=1, alpha=np.deg2rad(20)):\n",
" x = 0.\n",
" r_w = module * teeth / 2\n",
" y_p = worm_pitch_diameter / 2\n",
" x_p = worm_pitch_diameter / 2\n",
" r_thales = r_w / 2.\n",
" y_thales = y_p + r_thales\n",
" x_thales = y_p + r_thales\n",
" \n",
" def length(y):\n",
" return (x**2 + y**2)**(0.5)\n",
@@ -470,7 +501,7 @@
" \n",
" def z(y, t):\n",
" r = length(y)\n",
" return - module * num_threads * np.arcsin(x / r) / 2 + r * np.tan(alpha) + t\n",
" return - module * num_threads * np.arcsin(x / r) / 2 + (r-r_w) * np.tan(alpha) + t\n",
" \n",
" def dz_dy(y):\n",
" r = length(y)\n",
@@ -609,10 +640,131 @@
"part.show(part.makeLoft(curves_head))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "73769524-0356-4364-acbc-c4a28d26fc57",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t_start_1: -2.7474774194546225\n",
"t_start_0: 2.7474774194546225\n",
"t0: 0.7015390936864874, x0: 3.1224989948933315, min: 1.8775010319993481\n",
"t1: 0.7015390936864874, x1: 5.454356051426789, min: 0.47093369124192\n",
"t0: 0.5482381702072173, x0: 3.7996710369252895, min: 1.2005967588403554\n",
"t1: 0.5482381702072173, x1: 5.868347291705316, min: 0.8705739256491289\n",
"t0: -2.7474774194546225, x0: 4.0, min: 3.2681962153219666\n",
"t1: -2.7474774194546225, x1: 6.0, min: 3.2681962153219666\n",
"t0: -2.7218186874199746, x0: 3.7996710378205463, min: 3.1634473327759642\n",
"t1: -2.7218186874199746, x1: 5.868347293420843, min: 0.86835219843846\n",
"t0: 0.024534606456801573, x0: 3.1224989985781515, min: 1.877501936426569\n",
"t1: 0.024534606456801573, x1: 5.454356049869874, min: 0.45435622754073013\n"
]
}
],
"source": [
"import scipy as sp\n",
"import numpy as np\n",
"from freecad import part\n",
"from freecad import app\n",
"from pygears.transformation import numeric_transformation\n",
"\n",
"debug = False\n",
"def compute_involute(module=1, teeth=15, height=5, worm_pitch_diameter=10, num_threads=1, alpha=np.deg2rad(20)):\n",
" y = 0.\n",
" xw = worm_pitch_diameter / 2\n",
" \n",
" def length(x, y):\n",
" return (x**2 + y**2)**(0.5)\n",
" \n",
" def z(x, y, t):\n",
" r = length(x, y)\n",
" return module * num_threads * np.arcsin(y / r) / 2 + (r - xw) * np.tan(alpha) + t\n",
"\n",
" def distance_pw(x, y, t):\n",
" return np.sqrt((xw - x) ** 2 + z(x, y, t) ** 2)\n",
"\n",
" def min_root(x, y, t):\n",
" r0 = xw - module # * (1 + clearence)\n",
" x_t = sp.optimize.minimize(lambda x: distance_pw(x, y, t), (t)).x[0]\n",
" return distance_pw(x, y, t) + np.abs(r0**2 - x**2 - y**2)\n",
"\n",
" def min_head(x, y, t):\n",
" r1 = xw + module # * (1 + clearence)\n",
" return distance_pw(x, y, t) + np.abs(r1**2 - x**2 - y**2)\n",
" \n",
" xyz = [] \n",
" r0 = xw - module # * (1 + clearence)\n",
" r1 = xw + module # * (1 + clearence)\n",
" t_start_0 = (r0 - xw) / np.tan(alpha)\n",
" t_start_1 = (r1 - xw) / np.tan(alpha)\n",
"\n",
" \n",
" for y in np.linspace(-height / 2, height / 2, 20):\n",
" for t in np.linspace(t_start_0, t_start_1, 20):\n",
" x_t = sp.optimize.minimize(lambda x: distance_pw(x, y, t), xw).x[0]\n",
" z_t = z(x_t, y, t)\n",
" point = App.Vector(x_t, y, z_t)\n",
" part.show(part.Point(point).toShape())\n",
" \n",
" \n",
"compute_involute()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "26079daf-9e99-4365-89f4-c560e2aac9bd",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "expected ':' (2870794076.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[20], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m def debug_surface()\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m expected ':'\n"
]
}
],
"source": [
" def debug_surface()\n",
" x_i = np.linspace(r_w / 10., r_w * 3. / 2., 10)\n",
" y_i = np.linspace(-r_w, r_w, 10)\n",
" \n",
" \n",
" # Gitterpunkte berechnen\n",
" xv, yv = np.meshgrid(x_i, y_i)\n",
" zv = z(xv, yv)\n",
" \n",
" # Punkte für die B-Spline-Fläche erzeugen\n",
" points = []\n",
" for i in range(xv.shape[0]):\n",
" row = []\n",
" for j in range(xv.shape[1]):\n",
" point = FreeCAD.Vector(xv[i, j], yv[i, j], zv[i, j])\n",
" # part.show(part.Point(point).toShape())\n",
" row.append(point)\n",
" points.append(row)\n",
" \n",
" # B-Spline-Fläche erstellen\n",
" bspline_surface = Part.BSplineSurface()\n",
" bspline_surface.approximate(points)\n",
" \n",
" # Fläche in FreeCAD-Dokument einfügen\n",
" doc = FreeCAD.ActiveDocument if FreeCAD.ActiveDocument else FreeCAD.newDocument()\n",
" bspline_shape = Part.Shape(bspline_surface)\n",
" part_object = doc.addObject(\"Part::Feature\", \"BSplineSurface\")\n",
" part_object.Shape = bspline_shape\n",
" doc.recompute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfcc64d4-3756-431d-a78b-a81d30c5f6db",
"id": "e0bfeffb-7261-4976-8eb3-805af31d4bfd",
"metadata": {},
"outputs": [],
"source": []

File diff suppressed because one or more lines are too long

3092
pixi.lock

File diff suppressed because it is too large Load Diff

View File

@@ -20,3 +20,4 @@ sympy = ">=1.13.3,<2"
jupyter = ">=1.1.1,<2"
freecad = ">=1.0.0,<2"
pylint = ">=3.3.2,<4"
matplotlib = ">=3.10.0,<4"