Add more examples

This commit is contained in:
jimmy 2023-03-06 21:50:15 +13:00
parent b20fe5738d
commit e9340617ee
1 changed files with 255 additions and 86 deletions

View File

@ -12,7 +12,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"id": "a75c573b", "id": "a75c573b",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -34,15 +34,43 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"id": "25a01e9c", "id": "25a01e9c",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 3032\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 22\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2fb4234896484f178a27830ab615f08b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"c = cylinder(r=7, h=2)\n", "cyl = cylinder(r=7, h=2)\n",
"r.render(c)" "r.render(cyl)"
] ]
}, },
{ {
@ -57,12 +85,40 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"id": "ecdfd420-ebef-49b1-8d90-c35b1e5ac571", "id": "ecdfd420-ebef-49b1-8d90-c35b1e5ac571",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 728\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 6\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f3131bd71d4b44ffa01e86efeb64a525",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"c = cube((10,4,6)) #pass a tuple x, y, z\n", "c = cube((10,4,6)) #pass a tuple x, y, z\n",
"r.render(c)" "r.render(c)"
@ -90,7 +146,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": null,
"id": "77e99d01-1aa4-43ce-93bf-c71c6f1325c8", "id": "77e99d01-1aa4-43ce-93bf-c71c6f1325c8",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -106,7 +162,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": null,
"id": "bb5ad126-5476-43a8-9c8f-75aebce0c47e", "id": "bb5ad126-5476-43a8-9c8f-75aebce0c47e",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -133,7 +189,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": null,
"id": "86cb4b1a-03cf-449c-bc08-2ea81512c34a", "id": "86cb4b1a-03cf-449c-bc08-2ea81512c34a",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -157,7 +213,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"id": "a5769eb4-13d4-425a-a22b-8e14123f8908", "id": "a5769eb4-13d4-425a-a22b-8e14123f8908",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -177,7 +233,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": null,
"id": "6107bce9-ff24-4f94-974b-637445c707f5", "id": "6107bce9-ff24-4f94-974b-637445c707f5",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -205,7 +261,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"id": "c425603f-8c79-4e7b-b204-3c128768b6ab", "id": "c425603f-8c79-4e7b-b204-3c128768b6ab",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -225,46 +281,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"id": "9062af4f-d729-4208-abbf-1750b682b482", "id": "9062af4f-d729-4208-abbf-1750b682b482",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 4\n",
"Geometry cache size in bytes: 9824\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 65232\n",
"Total rendering time: 0:00:00.068\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 48\n",
" Halfedges: 144\n",
" Edges: 72\n",
" Halffacets: 52\n",
" Facets: 26\n",
" Volumes: 2\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "11a120f2cd4641279ef0d1f1af319eac",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"base = cube((5,5,2))\n", "base = cube((5,5,2))\n",
"inner = cylinder(r=0.5, h=5)\n", "inner = cylinder(r=0.5, h=5)\n",
@ -288,24 +310,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "1810ff24-c0f8-4c80-adc2-6985cd52d7dc", "id": "1810ff24-c0f8-4c80-adc2-6985cd52d7dc",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"ename": "NameError",
"evalue": "name 'scad_render_to_file' 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[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mscad_render_to_file\u001b[49m(part, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpart.scad\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'scad_render_to_file' is not defined"
]
}
],
"source": [ "source": [
"scad_render_to_file(part, \"part.scad\")" "scad_render_to_file(part, \"part.scad\")"
] ]
@ -320,38 +330,197 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": null,
"id": "44f345ad-417a-4783-b721-847351a13f4b", "id": "44f345ad-417a-4783-b721-847351a13f4b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Geometries in cache: 4\n",
"Geometry cache size in bytes: 3344\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 24912\n",
"Total rendering time: 0:00:00.018\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 18\n",
" Halfedges: 54\n",
" Edges: 27\n",
" Halffacets: 22\n",
" Facets: 11\n",
" Volumes: 2\n"
]
}
],
"source": [ "source": [
"! openscad -o part.stl part.scad" "! openscad -o part.stl part.scad"
] ]
}, },
{
"cell_type": "markdown",
"id": "c0c11a99-e3f6-4479-81d6-28715f84199f",
"metadata": {},
"source": [
"## Polyhedron"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "9866b676-247c-4a9b-a67d-0122d2932819",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 584\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 6\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "95a13583cb54495f85e760a9be96547c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'/home/jimmy/projects/Solid-Python-Demo/polyhedron.scad'"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = polyhedron(points = [\n",
" [2, 2, 2],\n",
" [2, 1, 2],\n",
" [2, 2 ,1],\n",
" [1, 2, 1],\n",
" [1, 3, 2]\n",
" ], \n",
" faces = [\n",
" [0 ,1, 2],\n",
" [0, 1, 3],\n",
" [1, 2, 3],\n",
" [2, 3, 4],\n",
" [0, 3, 4],\n",
" [0, 2, 4]\n",
" ]\n",
")\n",
"r.render(p)\n",
"scad_render_to_file(p, \"polyhedron.scad\")"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "cf0508f0-cd53-4161-aa5d-47ebd3a5af52",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 27\n",
"Geometry cache size in bytes: 79560\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 1358544\n",
"Total rendering time: 0:00:03.888\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 1008\n",
" Halfedges: 3024\n",
" Edges: 1512\n",
" Halffacets: 1012\n",
" Facets: 506\n",
" Volumes: 2\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ea6ccc6896874bb4a4c3ba5ce93ea251",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"base = cube((10, 10, 1))\n",
"for y in range(5):\n",
" for x in range(5):\n",
" base -= translate([x*2+1, y*2+1, 0])(cylinder(r=0.5, h=1))\n",
"r.render(base)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "ddd5c9a6-61e9-48d6-9755-354d48628ac0",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 111\n",
"Geometry cache size in bytes: 80808\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 482320\n",
"Total rendering time: 0:00:01.601\n",
" Top level object is a 3D object:\n",
" Simple: no\n",
" Vertices: 324\n",
" Halfedges: 1050\n",
" Edges: 525\n",
" Halffacets: 406\n",
" Facets: 203\n",
" Volumes: 2\n",
"WARNING: Object may not be a valid 2-manifold and may need repair!\n",
"EXPORT-WARNING: Exported object may not be a valid 2-manifold and may need repair\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cd1ce9b432e2425d989cf116cd0d61b8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from random import randint\n",
"base = cube((10, 10, 1))\n",
"for y in range(10):\n",
" for x in range(10):\n",
" base += translate([x, y, 0])(cube((1,1,randint(1,10))))\n",
"r.render(base)\n",
" "
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "ddbc58d3-c9e4-4187-908b-57f65658198a", "id": "173c5f9c-e99e-461d-a421-cb68a1ad6783",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []