Skip to content

Commit 88e2a11

Browse files
committed
point in box example
1 parent f04f302 commit 88e2a11

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

content/point-in-box.ipynb

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"trusted": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%pip install scipy pythreejs\n",
12+
"%pip install compas --no-deps\n",
13+
"%pip install compas_notebook --no-deps"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"metadata": {
20+
"trusted": true
21+
},
22+
"outputs": [],
23+
"source": [
24+
"from math import radians"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 3,
30+
"metadata": {
31+
"trusted": true
32+
},
33+
"outputs": [],
34+
"source": [
35+
"from compas.colors import Color\n",
36+
"from compas.geometry import Pointcloud\n",
37+
"from compas.geometry import Box\n",
38+
"from compas.geometry import Frame\n",
39+
"from compas.geometry import Sphere\n",
40+
"from compas_notebook import Viewer"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 4,
46+
"metadata": {
47+
"trusted": true
48+
},
49+
"outputs": [],
50+
"source": [
51+
"cloud = Pointcloud.from_bounds(10, 10, 10, 10000)"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 5,
57+
"metadata": {
58+
"trusted": true
59+
},
60+
"outputs": [],
61+
"source": [
62+
"box = Box(3, 2, 1)\n",
63+
"box.rotate(radians(30))\n",
64+
"box.translate(cloud.centroid)"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 6,
70+
"metadata": {
71+
"trusted": true
72+
},
73+
"outputs": [],
74+
"source": [
75+
"results = box.contains_points(cloud)\n",
76+
"\n",
77+
"inside = [point for point, result in zip(cloud, results) if result]\n",
78+
"outside = [point for point, result in zip(cloud, results) if not result]"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 7,
84+
"metadata": {
85+
"trusted": true
86+
},
87+
"outputs": [
88+
{
89+
"data": {
90+
"application/vnd.jupyter.widget-view+json": {
91+
"model_id": "a782d104dafa4283b5d4683af92dfade",
92+
"version_major": 2,
93+
"version_minor": 0
94+
},
95+
"text/plain": [
96+
"VBox(children=(HBox(children=(Button(icon='search-plus', layout=Layout(height='32px', width='48px'), style=But…"
97+
]
98+
},
99+
"metadata": {},
100+
"output_type": "display_data"
101+
}
102+
],
103+
"source": [
104+
"viewer = Viewer()\n",
105+
"viewer.scene.add(box.to_mesh(), show_faces=False, show_lines=True, linewidth=5)\n",
106+
"viewer.scene.add(Pointcloud(inside), color=Color.red(), pointsize=0.2)\n",
107+
"viewer.scene.add(Pointcloud(outside), color=Color.blue(), pointsize=0.1)\n",
108+
"viewer.show()"
109+
]
110+
}
111+
],
112+
"metadata": {
113+
"kernelspec": {
114+
"display_name": "Python (Pyodide)",
115+
"language": "python",
116+
"name": "python"
117+
},
118+
"language_info": {
119+
"codemirror_mode": {
120+
"name": "python",
121+
"version": 3
122+
},
123+
"file_extension": ".py",
124+
"mimetype": "text/x-python",
125+
"name": "python",
126+
"nbconvert_exporter": "python",
127+
"pygments_lexer": "ipython3",
128+
"version": "3.8"
129+
}
130+
},
131+
"nbformat": 4,
132+
"nbformat_minor": 4
133+
}

0 commit comments

Comments
 (0)