686 lines
33 KiB
Plaintext
686 lines
33 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "f027debb-4ad0-4ea0-a564-321f3c1bd63c",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Overwriting auto display for cadquery Workplane and Shape\n"
|
||
]
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"''"
|
||
]
|
||
},
|
||
"execution_count": 1,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"import timeit\n",
|
||
"tic = timeit.default_timer()\n",
|
||
"\n",
|
||
"import cadquery as cq\n",
|
||
"from math import sin, cos, pi\n",
|
||
"\n",
|
||
"\n",
|
||
"\n",
|
||
"from jupyter_cadquery import (\n",
|
||
" versions,\n",
|
||
" show, PartGroup, Part, \n",
|
||
" get_viewer, close_viewer, get_viewers, close_viewers, open_viewer, set_defaults, get_defaults, open_viewer,\n",
|
||
" get_pick,\n",
|
||
")\n",
|
||
"\n",
|
||
"from jupyter_cadquery.replay import replay, enable_replay, disable_replay\n",
|
||
"''"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "cde98536-33ac-4609-b1fe-50af35bdc752",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"id": "6af7a60f-ac0c-46cf-8956-a168cd3246cb",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"\n",
|
||
"Enabling jupyter_cadquery replay\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"cv = open_viewer(\"pretosius\",\n",
|
||
" anchor=\"right\", \n",
|
||
" glass=True, \n",
|
||
" tools=False) # sets default viewer\n",
|
||
"\n",
|
||
"\n",
|
||
"cv.grid = [not g for g in cv.widget.grid]\n",
|
||
"\n",
|
||
"cv.axes = not cv.axes\n",
|
||
"cv.axes0 = not cv.axes0\n",
|
||
"cv.transparent = not cv.transparent\n",
|
||
"cv.black_edges = not cv.black_edges\n",
|
||
"enable_replay(False, False)\n",
|
||
"show_object = replay"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "b943c6ad-a678-4af7-8139-b03cad539b33",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||
"Collecting git+https://github.com/gumyr/build123d\n",
|
||
" Cloning https://github.com/gumyr/build123d to /tmp/pip-req-build-_no6109s\n",
|
||
" Running command git clone --filter=blob:none --quiet https://github.com/gumyr/build123d /tmp/pip-req-build-_no6109s\n",
|
||
" fatal: unable to access 'https://github.com/gumyr/build123d/': Could not resolve host: github.com\n",
|
||
" \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n",
|
||
" \n",
|
||
" \u001b[31m×\u001b[0m \u001b[32mgit clone --\u001b[0m\u001b[32mfilter\u001b[0m\u001b[32m=\u001b[0m\u001b[32mblob\u001b[0m\u001b[32m:none --quiet \u001b[0m\u001b[4;32mhttps://github.com/gumyr/build123d\u001b[0m\u001b[32m \u001b[0m\u001b[32m/tmp/\u001b[0m\u001b[32mpip-req-build-_no6109s\u001b[0m did not run successfully.\n",
|
||
" \u001b[31m│\u001b[0m exit code: \u001b[1;36m128\u001b[0m\n",
|
||
" \u001b[31m╰─>\u001b[0m See above for output.\n",
|
||
" \n",
|
||
" \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n",
|
||
"\u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n",
|
||
"\n",
|
||
"\u001b[31m×\u001b[0m \u001b[32mgit clone --\u001b[0m\u001b[32mfilter\u001b[0m\u001b[32m=\u001b[0m\u001b[32mblob\u001b[0m\u001b[32m:none --quiet \u001b[0m\u001b[4;32mhttps://github.com/gumyr/build123d\u001b[0m\u001b[32m \u001b[0m\u001b[32m/tmp/\u001b[0m\u001b[32mpip-req-build-_no6109s\u001b[0m did not run successfully.\n",
|
||
"\u001b[31m│\u001b[0m exit code: \u001b[1;36m128\u001b[0m\n",
|
||
"\u001b[31m╰─>\u001b[0m See above for output.\n",
|
||
"\n",
|
||
"\u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n",
|
||
"\u001b[33mWARNING: There was an error checking the latest version of pip.\u001b[0m\u001b[33m\n",
|
||
"\u001b[0m"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"!pip install git+https://github.com/gumyr/build123d"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "44eb609a-c382-4d07-b224-d08cd3bf8107",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Solid at 0x7f27ec7477f0, Center(0.5, 1.0, 1.5)\n",
|
||
"└── Shell at 0x7f2857577f70, Center(0.5, 1.0, 1.5)\n",
|
||
" ├── Face at 0x7f2857577e70, Center(0.0, 1.0, 1.5)\n",
|
||
" ├── Face at 0x7f27ec747630, Center(1.0, 1.0, 1.5)\n",
|
||
" ├── Face at 0x7f27ec2af930, Center(0.5, 0.0, 1.5)\n",
|
||
" ├── Face at 0x7f27ec2e58b0, Center(0.5, 2.0, 1.5)\n",
|
||
" ├── Face at 0x7f27ec10cf70, Center(0.5, 1.0, 0.0)\n",
|
||
" └── Face at 0x7f27ec10fe30, Center(0.5, 1.0, 3.0)\n",
|
||
"\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from build123d import *\n",
|
||
"box=Solid.make_box(1,2,3)\n",
|
||
"print(box.show_topology(limit_class=\"Face\"))\n",
|
||
"box"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"id": "52baf674-915f-4a06-9015-61692f01601e",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<cad_viewer_widget.widget.CadViewer at 0x7f28585a1390>"
|
||
]
|
||
},
|
||
"execution_count": 9,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"width = 3\n",
|
||
"height = 6\n",
|
||
"ri = 10\n",
|
||
"ro = ri+0.3\n",
|
||
"\n",
|
||
"s = 0.8\n",
|
||
"s1 = 0.7\n",
|
||
"p = Pos(ri,0,0)\n",
|
||
"x = 1.8+ri\n",
|
||
"pad = 2\n",
|
||
"with BuildPart() as ring:\n",
|
||
" with BuildSketch(Plane.XZ) as sk:\n",
|
||
" with BuildLine() as outline:\n",
|
||
" c1 = Spline([(x,0,-pad),(x,0,height+pad)], tangents=[(1,0),(-1, 0)], tangent_scalars=[s,s])\n",
|
||
" c1 = Spline([(x,0,-pad),(x,0,height+pad)], tangents=[(-1,0),(1, 0)], tangent_scalars=[s1,s1])\n",
|
||
" make_face()\n",
|
||
" revolve(axis=Axis.Z)\n",
|
||
" \n",
|
||
" \n",
|
||
"\n",
|
||
"show(ring, transparent=True) \n",
|
||
"\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"id": "b9016caa-241a-4e76-a7ff-cad8cb0521bc",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"def string_to_binary_string(s:str):\n",
|
||
" return ''.join([\"{0:08b}\".format(ord(c)) for c in s])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "17ba4d69-d787-484f-b04e-a14668b1632b",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "ValueError",
|
||
"evalue": "Edges are disconnected",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[0;32mIn[6], line 68\u001b[0m\n\u001b[1;32m 66\u001b[0m binstr \u001b[38;5;241m=\u001b[39m string_to_binary_string(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmunsel\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 67\u001b[0m binstr \u001b[38;5;241m=\u001b[39m string_to_binary_string(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnonpostrans \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 68\u001b[0m signal \u001b[38;5;241m=\u001b[39m \u001b[43mbuild_signal\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbinstr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mri\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mwidth\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m0.4\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 69\u001b[0m show(signal,ring, transparent\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
|
||
"Cell \u001b[0;32mIn[6], line 61\u001b[0m, in \u001b[0;36mbuild_signal\u001b[0;34m(binstring, ri)\u001b[0m\n\u001b[1;32m 59\u001b[0m Circle(\u001b[38;5;241m0.5\u001b[39m)\n\u001b[1;32m 60\u001b[0m \u001b[38;5;66;03m#return path_builder\u001b[39;00m\n\u001b[0;32m---> 61\u001b[0m \u001b[43msweep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtransition\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mTransition\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mROUND\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m signal\n",
|
||
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/operations_generic.py:989\u001b[0m, in \u001b[0;36msweep\u001b[0;34m(sections, path, multisection, is_frenet, transition, normal, binormal, clean, mode)\u001b[0m\n\u001b[1;32m 987\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m context \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m context \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m context\u001b[38;5;241m.\u001b[39mpending_edges:\n\u001b[1;32m 988\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpath must be provided\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 989\u001b[0m path_wire \u001b[38;5;241m=\u001b[39m \u001b[43mWire\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcontext\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpending_edges\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 990\u001b[0m context\u001b[38;5;241m.\u001b[39mpending_edges \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 991\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
|
||
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/topology.py:7789\u001b[0m, in \u001b[0;36mWire.__init__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 7787\u001b[0m obj \u001b[38;5;241m=\u001b[39m wire\u001b[38;5;241m.\u001b[39mwrapped\n\u001b[1;32m 7788\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m edges:\n\u001b[0;32m-> 7789\u001b[0m obj \u001b[38;5;241m=\u001b[39m \u001b[43mWire\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_wire\u001b[49m\u001b[43m(\u001b[49m\u001b[43medges\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msequenced\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msequenced\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7791\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(\n\u001b[1;32m 7792\u001b[0m obj\u001b[38;5;241m=\u001b[39mobj,\n\u001b[1;32m 7793\u001b[0m label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m label \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m label,\n\u001b[1;32m 7794\u001b[0m color\u001b[38;5;241m=\u001b[39mcolor,\n\u001b[1;32m 7795\u001b[0m parent\u001b[38;5;241m=\u001b[39mparent,\n\u001b[1;32m 7796\u001b[0m )\n",
|
||
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/topology.py:8085\u001b[0m, in \u001b[0;36mWire._make_wire\u001b[0;34m(cls, edges, sequenced)\u001b[0m\n\u001b[1;32m 8083\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mWire is empty\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8084\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m wire_builder\u001b[38;5;241m.\u001b[39mError() \u001b[38;5;241m==\u001b[39m BRepBuilderAPI_DisconnectedWire:\n\u001b[0;32m-> 8085\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEdges are disconnected\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 8087\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m wire_builder\u001b[38;5;241m.\u001b[39mWire()\n",
|
||
"\u001b[0;31mValueError\u001b[0m: Edges are disconnected"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from math import sin, cos, pi\n",
|
||
"\n",
|
||
"width = 3\n",
|
||
"height = 6\n",
|
||
"ri = 10\n",
|
||
"ro = ri+0.3\n",
|
||
"\n",
|
||
"def build_signal(binstring, ri):\n",
|
||
" n = len(binstring)\n",
|
||
"\n",
|
||
" \n",
|
||
" ro = ri+1\n",
|
||
" dphi =2*pi/(n+0)\n",
|
||
" dp = dphi/10\n",
|
||
" dh = min(dp*ro, 18*pi/180)\n",
|
||
" \n",
|
||
" a = 1\n",
|
||
" tngu = lambda phi, d: (a*cos(phi), a*sin(phi), d)\n",
|
||
" tngd = lambda phi, d: (-a*cos(phi), -a*sin(phi), d)\n",
|
||
"\n",
|
||
" with BuildPart() as signal:\n",
|
||
" with BuildLine(Plane.XY) as path_builder:\n",
|
||
" segments = []\n",
|
||
" h = 0 if binstring[0] == \"0\" else height\n",
|
||
" same_bits_streak = 0\n",
|
||
" for i, b in enumerate(binstring):\n",
|
||
" pos_flank = b == \"0\" and binstring[(i+1)%n] == \"1\"\n",
|
||
" neg_flank = b == \"1\" and binstring[(i+1)%n] == \"0\"\n",
|
||
" same_bits_streak += 1\n",
|
||
" if neg_flank or pos_flank or (i == n-1):\n",
|
||
" phi0 = dphi*(i-same_bits_streak+1)\n",
|
||
" phi1 = dphi*(i-same_bits_streak+1+0.5*same_bits_streak)\n",
|
||
" phi2 = dphi*(i+1)\n",
|
||
" phi0_pad = phi0 + dp\n",
|
||
" phi2_pad = phi2 - dp\n",
|
||
" #if segments:\n",
|
||
" # segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
|
||
" segments.append(ThreePointArc(\n",
|
||
" (ri * cos(phi0_pad), ri * sin(phi0_pad),h),\n",
|
||
" (ri * cos(phi1), ri * sin(phi1),h),\n",
|
||
" (ri * cos(phi2_pad), ri * sin(phi2_pad),h),\n",
|
||
" ))\n",
|
||
" same_bits_streak = 0\n",
|
||
" p1 = (ri * cos(phi2), ri * sin(phi2),height-dh)\n",
|
||
" p2 = (ri * cos(phi2), ri * sin(phi2),dh)\n",
|
||
" #l = segments[i]\n",
|
||
" if neg_flank:\n",
|
||
" h = 0\n",
|
||
" segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
|
||
" segments.append(Spline(p1,p2,\n",
|
||
" tangents=[tngu(phi2, -1), tngd(phi2, -1)]))\n",
|
||
" if pos_flank:\n",
|
||
" h = height\n",
|
||
" segments.append(Spline(p2,p1,\n",
|
||
" tangents=[tngu(phi2, 1), tngd(phi2, 1)]))\n",
|
||
"\n",
|
||
" # l1 = segments[0]\n",
|
||
" with BuildSketch(Plane( segments[0] @ 0, z_dir=segments[0] % 0)) as x_section:\n",
|
||
" Circle(0.5)\n",
|
||
" #return path_builder\n",
|
||
" sweep(transition=Transition.ROUND)\n",
|
||
" return signal\n",
|
||
"\n",
|
||
"binstr = '0101100'#\n",
|
||
"binstr = '1101000'#\n",
|
||
"binstr = string_to_binary_string(\"munsel\")\n",
|
||
"binstr = string_to_binary_string(\"nonpostrans \")\n",
|
||
"signal = build_signal(binstr, ri+width+0.4)\n",
|
||
"show(signal,ring, transparent=True)\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 15,
|
||
"id": "7646c441-da20-47e2-9047-fb4a02a0a85d",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"100% ⋮————————————————————————————————————————————————————————————⋮ (2/2) 0.02s\n"
|
||
]
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"<cad_viewer_widget.widget.CadViewer at 0x7f28585a1390>"
|
||
]
|
||
},
|
||
"execution_count": 15,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"\n",
|
||
"def build_signal(binstring, ri):\n",
|
||
" n = len(binstring)\n",
|
||
" ro = ri+1\n",
|
||
" dphi =2*pi/(n+0) # how much angle per bit\n",
|
||
" dp = 0.81/ri/pi#dphi/10 # how much of that used for curvature\n",
|
||
" dh = min(dp*ro, 10*pi/180)\n",
|
||
" \n",
|
||
" a = 1\n",
|
||
" tngu = lambda phi, d: (a*cos(phi), a*sin(phi), d)\n",
|
||
" tngd = lambda phi, d: (-a*cos(phi), -a*sin(phi), d)\n",
|
||
" \n",
|
||
" def build_segments(pre_segments=[]):\n",
|
||
" segments = []\n",
|
||
" h = 0 if binstring[0] == \"0\" else height\n",
|
||
" same_bits_streak = 0\n",
|
||
" i_hoz = 0\n",
|
||
" ns = len(pre_segments)\n",
|
||
" for i, b in enumerate(binstring):\n",
|
||
" pos_flank = b == \"0\" and binstring[(i+1)%n] == \"1\"\n",
|
||
" neg_flank = b == \"1\" and binstring[(i+1)%n] == \"0\"\n",
|
||
" same_bits_streak += 1\n",
|
||
" if neg_flank or pos_flank or (i == n-1):\n",
|
||
" phi0 = dphi*(i-same_bits_streak+1)\n",
|
||
" phi1 = dphi*(i-same_bits_streak+1+0.5*same_bits_streak)\n",
|
||
" phi2 = dphi*(i+1)\n",
|
||
" phi0_pad = phi0 + dp\n",
|
||
" phi2_pad = phi2 - dp\n",
|
||
" #if segments:\n",
|
||
" # segments.append(Spline(segments[-1]@1,p1, tangents=[segments[-1]%1, tngu(phi2, -1)]))\n",
|
||
" segments.append(ThreePointArc(\n",
|
||
" (ri * cos(phi0_pad), ri * sin(phi0_pad),h),\n",
|
||
" (ri * cos(phi1), ri * sin(phi1),h),\n",
|
||
" (ri * cos(phi2_pad), ri * sin(phi2_pad),h),\n",
|
||
" ))\n",
|
||
" i_hoz += 1\n",
|
||
" same_bits_streak = 0\n",
|
||
" p1 = (ri * cos(phi2), ri * sin(phi2),height-dh)\n",
|
||
" p2 = (ri * cos(phi2), ri * sin(phi2),dh)\n",
|
||
" #l = segments[i]\n",
|
||
" if neg_flank:\n",
|
||
" h = 0\n",
|
||
" if pre_segments:\n",
|
||
" segments.append(Spline(pre_segments[i_hoz-1]@1,p1, tangents=[pre_segments[i_hoz-1]%1, tngu(phi2, -1)]))\n",
|
||
" segments.append(Spline(p1,p2,\n",
|
||
" tangents=[tngu(phi2, -1), tngd(phi2, -1)]))\n",
|
||
" segments.append(Spline(p2, pre_segments[i_hoz%ns]@0, tangents=[tngd(phi2, -1), pre_segments[i_hoz%ns]%0]))\n",
|
||
" if pos_flank:\n",
|
||
" h = height\n",
|
||
" if pre_segments:\n",
|
||
" segments.append(Spline(pre_segments[i_hoz-1]@1,p2, tangents=[pre_segments[i_hoz-1]%1, tngu(phi2, 1)]))\n",
|
||
" segments.append(Spline(p2,p1,\n",
|
||
" tangents=[tngu(phi2, 1), tngd(phi2, 1)]))\n",
|
||
" segments.append(Spline(p1, pre_segments[i_hoz%ns]@0, tangents=[tngd(phi2, 1), pre_segments[i_hoz%ns]%0]))\n",
|
||
"\n",
|
||
" return segments\n",
|
||
" \n",
|
||
" pre_segments = build_segments()#???\n",
|
||
"\n",
|
||
"\n",
|
||
" with BuildPart() as signal:\n",
|
||
" with BuildLine(Plane.XY) as path_builder:\n",
|
||
" #path_builder.mode=Mode.PRIVATE\n",
|
||
" segments = build_segments(pre_segments)\n",
|
||
" #segments = build_segments()\n",
|
||
" # l1 = segments[0]\n",
|
||
" with BuildSketch(Plane(segments[0] @ 0, z_dir=segments[0] % 0)) as x_section:\n",
|
||
" Circle(0.4)\n",
|
||
" #Rectangle(0.8,0.8)\n",
|
||
" #return path_builder\n",
|
||
" sweep()\n",
|
||
" #sweep(transition=Transition.ROUND)\n",
|
||
" signal.label=\"decor\"\n",
|
||
" #return pre_segments\n",
|
||
" return path_builder\n",
|
||
" #return signal\n",
|
||
"\n",
|
||
"#binstr = '0101100'#\n",
|
||
"#binstr = '110101000'#\n",
|
||
"#binstr = string_to_binary_string(\"munsel\")\n",
|
||
"binstr = string_to_binary_string(\"salty\")\n",
|
||
"signal = build_signal(binstr, ri+width+0.3)\n",
|
||
"show(signal,ring, transparent=True)\n",
|
||
"#show(signal, transparent=True, reset_camera=False)\n",
|
||
" "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 14,
|
||
"id": "d2d71180-9e82-4907-9579-e1accdb756e7",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "AttributeError",
|
||
"evalue": "'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[0;32mIn[14], line 10\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (left, right)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;66;03m#ld, lu = \u001b[39;00m\n\u001b[0;32m---> 10\u001b[0m a,b,c,d \u001b[38;5;241m=\u001b[39m split_part(\u001b[43msignal\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpart\u001b[49m)\n\u001b[1;32m 11\u001b[0m \u001b[38;5;66;03m#cv = show(ld,lu, axes=True, axes0=True, transparent=True)\u001b[39;00m\n",
|
||
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/build_common.py:761\u001b[0m, in \u001b[0;36mBuilder.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 759\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name):\n\u001b[1;32m 760\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The user is likely trying to reference the builder's object\"\"\"\u001b[39;00m\n\u001b[0;32m--> 761\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\n\u001b[1;32m 762\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 763\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDid you intend \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m<\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_obj_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 764\u001b[0m )\n",
|
||
"\u001b[0;31mAttributeError\u001b[0m: 'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"def split_part(part):\n",
|
||
" #left, right = \n",
|
||
" return split(part, bisect_by=Plane.XZ, keep=Keep.BOTH).solids()\n",
|
||
" #ld, lu = split(left,bisect_by=Plane.YZ, keep=Keep.BOTH).solids()\n",
|
||
" #rd, ru = split(right,bisect_by=Plane.YZ, keep=Keep.BOTH).solids()\n",
|
||
" #return ld, lu#, rd, ru\n",
|
||
" return (left, right)\n",
|
||
"\n",
|
||
"#ld, lu = \n",
|
||
"a,b,c,d = split_part(signal.part)\n",
|
||
"#cv = show(ld,lu, axes=True, axes0=True, transparent=True)\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 13,
|
||
"id": "71186b01-15d9-4cdc-b70c-f94f75106ef9",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "NameError",
|
||
"evalue": "name 'd' is not defined",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43md\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m#neg_ring = ring.part - signal.part\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m#show(neg_ring)\u001b[39;00m\n",
|
||
"\u001b[0;31mNameError\u001b[0m: name 'd' is not defined"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"d\n",
|
||
"#neg_ring = ring.part - signal.part\n",
|
||
"#show(neg_ring)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 12,
|
||
"id": "e6b70bbb-5ceb-4440-ab01-7caeb06c6f17",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "AttributeError",
|
||
"evalue": "'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m product \u001b[38;5;241m=\u001b[39m Compound(label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mring\u001b[39m\u001b[38;5;124m\"\u001b[39m, children\u001b[38;5;241m=\u001b[39m[ring\u001b[38;5;241m.\u001b[39mpart, \u001b[43msignal\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpart\u001b[49m])\n\u001b[1;32m 2\u001b[0m show(product)\n",
|
||
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/build123d/build_common.py:761\u001b[0m, in \u001b[0;36mBuilder.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 759\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, name):\n\u001b[1;32m 760\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"The user is likely trying to reference the builder's object\"\"\"\u001b[39;00m\n\u001b[0;32m--> 761\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(\n\u001b[1;32m 762\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m has no attribute \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 763\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDid you intend \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m<\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_obj_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m?\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 764\u001b[0m )\n",
|
||
"\u001b[0;31mAttributeError\u001b[0m: 'BuildLine' has no attribute 'part'. Did you intend '<BuildLine>.line.part'?"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"product = Compound(label=\"ring\", children=[ring.part, signal.part])\n",
|
||
"show(product)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "4d278f9c-5e81-4341-89bd-6840d21028da",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"#show(signal)\n",
|
||
"product.export_step(\"nonpostrans_ascii_ring.step\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "a0f50802-29c0-4960-918b-245c9b71a3e9",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"fullring = ring.part + signal.part"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "3d306d91-b798-445a-b91c-e99887d539df",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"#cq.exporters.export(signal, \"signal.stl\", cq.exporters.ExportTypes.STL)\n",
|
||
"\n",
|
||
"view_port_origin=(-100, -50, 30)\n",
|
||
"visible, hidden = ring.project_to_viewport(view_port_origin)\n",
|
||
"\n",
|
||
"max_dimension = max(*Compound(children=visible + hidden).bounding_box().size)\n",
|
||
"exporter = ExportSVG(scale=100 / max_dimension)\n",
|
||
"exporter.add_layer(\"Visible\")\n",
|
||
"exporter.add_layer(\"Hidden\", line_color=(99, 99, 99), line_type=LineType.ISO_DOT)\n",
|
||
"exporter.add_shape(visible, layer=\"Visible\")\n",
|
||
"exporter.add_shape(hidden, layer=\"Hidden\")\n",
|
||
"exporter.write(\"nonpostrans_ring.svg\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "8a5cfcf5-9811-4004-8f29-d56fa444a399",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"from build123d import *\n",
|
||
"import copy"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 11,
|
||
"id": "c485de3b-7837-496a-9664-283ed97ea2d9",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"w_cut_inside = 71.0 w_cut_outside = 21.0\n",
|
||
"w_cut_inside = 71.0 w_cut_outside = 21.0\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"def build_psorias_release(L = 216, W = 127, H = 135,PEAK2PEAK = 160, h_bottom = 15):\n",
|
||
"\n",
|
||
" R0 = 40\n",
|
||
" R1 = 8\n",
|
||
" R2 = 40\n",
|
||
" R3 = 30\n",
|
||
" w_cut_inside = (PEAK2PEAK / 2) - R1-1\n",
|
||
" w_cut_outside = (L / 2) - w_cut_inside - (2 * R1)\n",
|
||
" print(f\"{w_cut_inside = } {w_cut_outside = }\")\n",
|
||
" \n",
|
||
" h_bend = 70\n",
|
||
" w_bend = w_cut_outside - 8\n",
|
||
" h_rect = 10\n",
|
||
" w_slope = 10\n",
|
||
"\n",
|
||
"\n",
|
||
" with BuildPart() as p:\n",
|
||
" with BuildSketch(Plane.XZ) as s:\n",
|
||
" with Locations((0,H-R0)):\n",
|
||
" Circle(R0)\n",
|
||
" with Locations((0,0)):\n",
|
||
" Rectangle(W, h_rect)\n",
|
||
" make_hull()\n",
|
||
" extrude(amount=L/2)\n",
|
||
" with BuildSketch(Plane.YZ.offset(-W/2)) as s:\n",
|
||
" with Locations((-(L-w_cut_inside)/2, H+h_rect/2)):\n",
|
||
" Rectangle(w_cut_inside, h_rect)\n",
|
||
" with Locations(((-L+w_cut_inside-w_slope-R2-1)/2, h_bottom+h_rect/2)): \n",
|
||
" Rectangle(w_cut_inside-w_slope-R2, h_rect)\n",
|
||
" with Locations((-(L-w_cut_inside+R2-w_slope)/2, h_bottom+R2)): \n",
|
||
" Circle(R2)\n",
|
||
" make_hull()\n",
|
||
" extrude(amount=W, mode=Mode.SUBTRACT)\n",
|
||
" with BuildSketch(Plane.YZ.offset(-W/2)) as s:\n",
|
||
" with Locations((-w_cut_outside/2, H+h_rect/2)):\n",
|
||
" Rectangle(w_cut_outside, h_rect)\n",
|
||
" with Locations(((h_rect)/2, h_rect)): \n",
|
||
" Rectangle(h_rect, h_rect)\n",
|
||
" with Locations((-w_bend+R3, h_bend)): \n",
|
||
" Circle(R3)\n",
|
||
" make_hull()\n",
|
||
" extrude(amount=W, mode=Mode.SUBTRACT) \n",
|
||
" fillet(p.edges().sort_by(Axis.Z)[-1], radius=R1) \n",
|
||
" fillet(p.edges().sort_by(Axis.Z)[-3], radius=R1)\n",
|
||
" #scale(by=(1,1,0.8), mode=Mode.SUBTRACT)\n",
|
||
" mirror(p.part, about=Plane(p.faces().group_by(Axis.Y)[0][0]))\n",
|
||
" return p\n",
|
||
"\n",
|
||
"p = build_psorias_release()\n",
|
||
"p1 = build_psorias_release(L = 216, W = 110, H = 100,PEAK2PEAK = 160, h_bottom = 15)\n",
|
||
"p2 = p.part - p1.part.locate(Location((0.,0,-25.)))\n",
|
||
"\n",
|
||
"p2"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "bfe10241-66e6-43c9-839e-16f1dfbe2925",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"p1 = copy.copy(p.part)\n",
|
||
"p1 = scale(p1, by=(0.8,0.95,0.8)).locate(Location((0.,-(1-0.95)*W/2.-2.5,-25.)))\n",
|
||
"p2 = p.part-p1"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "bc50e074-b223-4c10-9dc4-bbece6206876",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"p2.export_step(\"psoas_releaser.step\")\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "beae3c3c-7cea-40f3-9e30-10b87e8fcbdd",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import build123d as b1 \n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "016ae351-fc44-456c-834a-15cb59e42327",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"b1.topology."
|
||
]
|
||
}
|
||
],
|
||
"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.10.8"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|