COMPAS 2.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. compas/__init__.py +274 -0
  2. compas/__main__.py +31 -0
  3. compas/_iotools.py +80 -0
  4. compas/_os.py +746 -0
  5. compas/colors/__init__.py +14 -0
  6. compas/colors/cmcrameri/acton.txt +256 -0
  7. compas/colors/cmcrameri/actonS.txt +100 -0
  8. compas/colors/cmcrameri/bam.txt +256 -0
  9. compas/colors/cmcrameri/bamO.txt +256 -0
  10. compas/colors/cmcrameri/bamako.txt +256 -0
  11. compas/colors/cmcrameri/bamakoS.txt +100 -0
  12. compas/colors/cmcrameri/batlow.txt +256 -0
  13. compas/colors/cmcrameri/batlowK.txt +256 -0
  14. compas/colors/cmcrameri/batlowS.txt +100 -0
  15. compas/colors/cmcrameri/batlowW.txt +256 -0
  16. compas/colors/cmcrameri/berlin.txt +256 -0
  17. compas/colors/cmcrameri/bilbao.txt +256 -0
  18. compas/colors/cmcrameri/bilbaoS.txt +100 -0
  19. compas/colors/cmcrameri/broc.txt +256 -0
  20. compas/colors/cmcrameri/brocO.txt +256 -0
  21. compas/colors/cmcrameri/buda.txt +256 -0
  22. compas/colors/cmcrameri/budaS.txt +100 -0
  23. compas/colors/cmcrameri/bukavu.txt +256 -0
  24. compas/colors/cmcrameri/cork.txt +256 -0
  25. compas/colors/cmcrameri/corkO.txt +256 -0
  26. compas/colors/cmcrameri/davos.txt +256 -0
  27. compas/colors/cmcrameri/davosS.txt +100 -0
  28. compas/colors/cmcrameri/devon.txt +256 -0
  29. compas/colors/cmcrameri/devonS.txt +100 -0
  30. compas/colors/cmcrameri/fes.txt +256 -0
  31. compas/colors/cmcrameri/grayC.txt +256 -0
  32. compas/colors/cmcrameri/grayCS.txt +100 -0
  33. compas/colors/cmcrameri/hawaii.txt +256 -0
  34. compas/colors/cmcrameri/hawaiiS.txt +100 -0
  35. compas/colors/cmcrameri/imola.txt +256 -0
  36. compas/colors/cmcrameri/imolaS.txt +100 -0
  37. compas/colors/cmcrameri/lajolla.txt +256 -0
  38. compas/colors/cmcrameri/lajollaS.txt +100 -0
  39. compas/colors/cmcrameri/lapaz.txt +256 -0
  40. compas/colors/cmcrameri/lapazS.txt +100 -0
  41. compas/colors/cmcrameri/lisbon.txt +256 -0
  42. compas/colors/cmcrameri/nuuk.txt +256 -0
  43. compas/colors/cmcrameri/nuukS.txt +100 -0
  44. compas/colors/cmcrameri/oleron.txt +256 -0
  45. compas/colors/cmcrameri/oslo.txt +256 -0
  46. compas/colors/cmcrameri/osloS.txt +100 -0
  47. compas/colors/cmcrameri/roma.txt +256 -0
  48. compas/colors/cmcrameri/romaO.txt +256 -0
  49. compas/colors/cmcrameri/tofino.txt +256 -0
  50. compas/colors/cmcrameri/tokyo.txt +256 -0
  51. compas/colors/cmcrameri/tokyoS.txt +100 -0
  52. compas/colors/cmcrameri/turku.txt +256 -0
  53. compas/colors/cmcrameri/turkuS.txt +100 -0
  54. compas/colors/cmcrameri/vanimo.txt +256 -0
  55. compas/colors/cmcrameri/vik.txt +256 -0
  56. compas/colors/cmcrameri/vikO.txt +256 -0
  57. compas/colors/color.py +1118 -0
  58. compas/colors/colordict.py +103 -0
  59. compas/colors/colormap.py +306 -0
  60. compas/colors/html_colors.py +149 -0
  61. compas/colors/mpl_colormap.py +1064 -0
  62. compas/data/__init__.py +31 -0
  63. compas/data/coercion.py +71 -0
  64. compas/data/conftest.py +10 -0
  65. compas/data/data.py +342 -0
  66. compas/data/encoders.py +240 -0
  67. compas/data/exceptions.py +2 -0
  68. compas/data/json.py +240 -0
  69. compas/data/samples/boxes.obj +250 -0
  70. compas/data/samples/butt_model.obj +2829 -0
  71. compas/data/samples/cone.stl +0 -0
  72. compas/data/samples/cube.off +16 -0
  73. compas/data/samples/cube_ascii.stl +56114 -0
  74. compas/data/samples/cube_binary.stl +0 -0
  75. compas/data/samples/cube_binary_2.stl +0 -0
  76. compas/data/samples/doosabin.json +1 -0
  77. compas/data/samples/faces.obj +63 -0
  78. compas/data/samples/faces_big.obj +9663 -0
  79. compas/data/samples/faces_reversed.obj +63 -0
  80. compas/data/samples/fink.obj +135 -0
  81. compas/data/samples/grid_irregular.obj +303 -0
  82. compas/data/samples/hypar.obj +148 -0
  83. compas/data/samples/lines.json +1 -0
  84. compas/data/samples/lines.obj +282 -0
  85. compas/data/samples/lines_big.obj +40322 -0
  86. compas/data/samples/lines_bigger.obj +161282 -0
  87. compas/data/samples/lines_noleaves.obj +422 -0
  88. compas/data/samples/mesh.obj +874 -0
  89. compas/data/samples/mesh_100_faces.json +1893 -0
  90. compas/data/samples/mesh_110_faces.json +2081 -0
  91. compas/data/samples/open_edges.obj +424 -0
  92. compas/data/samples/point.json +1 -0
  93. compas/data/samples/quadmesh.obj +183 -0
  94. compas/data/samples/quadmesh_planar.obj +181 -0
  95. compas/data/samples/saddle.obj +314 -0
  96. compas/data/samples/spline.obj +72 -0
  97. compas/data/samples/tubemesh.json +1 -0
  98. compas/data/samples/tubemesh.obj +378 -0
  99. compas/data/samples/tubemesh.off +374 -0
  100. compas/data/samples/tubemesh.ply +551 -0
  101. compas/data/schema.py +137 -0
  102. compas/data/validators.py +243 -0
  103. compas/datastructures/__init__.py +75 -0
  104. compas/datastructures/_mutablemapping.py +148 -0
  105. compas/datastructures/assembly/__init__.py +0 -0
  106. compas/datastructures/assembly/assembly.py +234 -0
  107. compas/datastructures/assembly/exceptions.py +6 -0
  108. compas/datastructures/assembly/part.py +228 -0
  109. compas/datastructures/attributes.py +85 -0
  110. compas/datastructures/cell_network/__init__.py +0 -0
  111. compas/datastructures/cell_network/cell_network.py +4190 -0
  112. compas/datastructures/datastructure.py +309 -0
  113. compas/datastructures/graph/__init__.py +0 -0
  114. compas/datastructures/graph/duality.py +197 -0
  115. compas/datastructures/graph/graph.py +2478 -0
  116. compas/datastructures/graph/operations/__init__.py +0 -0
  117. compas/datastructures/graph/operations/join.py +124 -0
  118. compas/datastructures/graph/operations/split.py +63 -0
  119. compas/datastructures/graph/planarity.py +292 -0
  120. compas/datastructures/graph/smoothing.py +59 -0
  121. compas/datastructures/mesh/__init__.py +0 -0
  122. compas/datastructures/mesh/conway.py +553 -0
  123. compas/datastructures/mesh/duality.py +104 -0
  124. compas/datastructures/mesh/mesh.py +5103 -0
  125. compas/datastructures/mesh/operations/__init__.py +0 -0
  126. compas/datastructures/mesh/operations/collapse.py +350 -0
  127. compas/datastructures/mesh/operations/extrude.py +0 -0
  128. compas/datastructures/mesh/operations/insert.py +120 -0
  129. compas/datastructures/mesh/operations/merge.py +83 -0
  130. compas/datastructures/mesh/operations/split.py +263 -0
  131. compas/datastructures/mesh/operations/substitute.py +37 -0
  132. compas/datastructures/mesh/operations/swap.py +62 -0
  133. compas/datastructures/mesh/operations/weld.py +107 -0
  134. compas/datastructures/mesh/remesh.py +234 -0
  135. compas/datastructures/mesh/slice.py +170 -0
  136. compas/datastructures/mesh/smoothing.py +187 -0
  137. compas/datastructures/mesh/subdivision.py +754 -0
  138. compas/datastructures/tree/__init__.py +0 -0
  139. compas/datastructures/tree/tree.py +504 -0
  140. compas/datastructures/volmesh/__init__.py +0 -0
  141. compas/datastructures/volmesh/volmesh.py +4203 -0
  142. compas/files/__init__.py +27 -0
  143. compas/files/_xml/__init__.py +0 -0
  144. compas/files/_xml/xml_cli.py +213 -0
  145. compas/files/_xml/xml_cpython.py +32 -0
  146. compas/files/_xml/xml_pre_38.py +58 -0
  147. compas/files/_xml/xml_shared.py +40 -0
  148. compas/files/gltf/__init__.py +0 -0
  149. compas/files/gltf/constants.py +59 -0
  150. compas/files/gltf/data_classes.py +657 -0
  151. compas/files/gltf/extensions.py +317 -0
  152. compas/files/gltf/gltf.py +92 -0
  153. compas/files/gltf/gltf_children.py +64 -0
  154. compas/files/gltf/gltf_content.py +615 -0
  155. compas/files/gltf/gltf_exporter.py +465 -0
  156. compas/files/gltf/gltf_mesh.py +273 -0
  157. compas/files/gltf/gltf_node.py +348 -0
  158. compas/files/gltf/gltf_parser.py +115 -0
  159. compas/files/gltf/gltf_reader.py +310 -0
  160. compas/files/gltf/gltf_scene.py +125 -0
  161. compas/files/gltf/helpers.py +59 -0
  162. compas/files/obj.py +680 -0
  163. compas/files/off.py +296 -0
  164. compas/files/ply.py +697 -0
  165. compas/files/stl.py +436 -0
  166. compas/files/xml.py +328 -0
  167. compas/geometry/__init__.py +772 -0
  168. compas/geometry/_core/__init__.py +0 -0
  169. compas/geometry/_core/_algebra.py +2826 -0
  170. compas/geometry/_core/angles.py +408 -0
  171. compas/geometry/_core/centroids.py +573 -0
  172. compas/geometry/_core/distance.py +895 -0
  173. compas/geometry/_core/normals.py +149 -0
  174. compas/geometry/_core/nurbs.py +367 -0
  175. compas/geometry/_core/predicates_2.py +582 -0
  176. compas/geometry/_core/predicates_3.py +1111 -0
  177. compas/geometry/_core/quaternions.py +196 -0
  178. compas/geometry/_core/size.py +204 -0
  179. compas/geometry/_core/tangent.py +56 -0
  180. compas/geometry/_core/transformations.py +1121 -0
  181. compas/geometry/_core/transformations_numpy.py +279 -0
  182. compas/geometry/bbox.py +145 -0
  183. compas/geometry/bbox_numpy.py +306 -0
  184. compas/geometry/bestfit.py +77 -0
  185. compas/geometry/bestfit_numpy.py +259 -0
  186. compas/geometry/booleans.py +297 -0
  187. compas/geometry/booleans_shapely.py +147 -0
  188. compas/geometry/brep/__init__.py +112 -0
  189. compas/geometry/brep/brep.py +1131 -0
  190. compas/geometry/brep/edge.py +302 -0
  191. compas/geometry/brep/errors.py +22 -0
  192. compas/geometry/brep/face.py +329 -0
  193. compas/geometry/brep/loop.py +87 -0
  194. compas/geometry/brep/trim.py +46 -0
  195. compas/geometry/brep/vertex.py +46 -0
  196. compas/geometry/contours.py +32 -0
  197. compas/geometry/curves/__init__.py +0 -0
  198. compas/geometry/curves/arc.py +429 -0
  199. compas/geometry/curves/bezier.py +345 -0
  200. compas/geometry/curves/circle.py +500 -0
  201. compas/geometry/curves/conic.py +16 -0
  202. compas/geometry/curves/curve.py +614 -0
  203. compas/geometry/curves/ellipse.py +408 -0
  204. compas/geometry/curves/hyperbola.py +336 -0
  205. compas/geometry/curves/line.py +431 -0
  206. compas/geometry/curves/nurbs.py +412 -0
  207. compas/geometry/curves/parabola.py +256 -0
  208. compas/geometry/curves/polyline.py +724 -0
  209. compas/geometry/frame.py +769 -0
  210. compas/geometry/geometry.py +296 -0
  211. compas/geometry/hull.py +146 -0
  212. compas/geometry/hull_numpy.py +82 -0
  213. compas/geometry/icp_numpy.py +104 -0
  214. compas/geometry/interpolation_barycentric.py +38 -0
  215. compas/geometry/interpolation_coons.py +102 -0
  216. compas/geometry/interpolation_tweening.py +87 -0
  217. compas/geometry/intersection.py +121 -0
  218. compas/geometry/intersections.py +1105 -0
  219. compas/geometry/kdtree.py +153 -0
  220. compas/geometry/offset.py +208 -0
  221. compas/geometry/pca_numpy.py +87 -0
  222. compas/geometry/plane.py +657 -0
  223. compas/geometry/point.py +664 -0
  224. compas/geometry/pointcloud.py +409 -0
  225. compas/geometry/polygon.py +473 -0
  226. compas/geometry/polyhedron.py +650 -0
  227. compas/geometry/projection.py +155 -0
  228. compas/geometry/quadmesh_planarize.py +30 -0
  229. compas/geometry/quadmesh_planarize_none.py +114 -0
  230. compas/geometry/quaternion.py +544 -0
  231. compas/geometry/reflection.py +102 -0
  232. compas/geometry/rotation.py +354 -0
  233. compas/geometry/scale.py +100 -0
  234. compas/geometry/shapes/__init__.py +0 -0
  235. compas/geometry/shapes/box.py +747 -0
  236. compas/geometry/shapes/capsule.py +472 -0
  237. compas/geometry/shapes/cone.py +309 -0
  238. compas/geometry/shapes/cylinder.py +355 -0
  239. compas/geometry/shapes/shape.py +300 -0
  240. compas/geometry/shapes/sphere.py +362 -0
  241. compas/geometry/shapes/torus.py +294 -0
  242. compas/geometry/shear.py +115 -0
  243. compas/geometry/surfaces/__init__.py +0 -0
  244. compas/geometry/surfaces/conical.py +166 -0
  245. compas/geometry/surfaces/cylindrical.py +251 -0
  246. compas/geometry/surfaces/extrusion.py +0 -0
  247. compas/geometry/surfaces/nurbs.py +380 -0
  248. compas/geometry/surfaces/planar.py +223 -0
  249. compas/geometry/surfaces/revolution.py +0 -0
  250. compas/geometry/surfaces/spherical.py +259 -0
  251. compas/geometry/surfaces/surface.py +689 -0
  252. compas/geometry/surfaces/toroidal.py +198 -0
  253. compas/geometry/transformation.py +554 -0
  254. compas/geometry/translation.py +104 -0
  255. compas/geometry/triangulation_delaunay.py +102 -0
  256. compas/geometry/triangulation_earclip.py +300 -0
  257. compas/geometry/trimesh_curvature.py +113 -0
  258. compas/geometry/trimesh_descent_numpy.py +26 -0
  259. compas/geometry/trimesh_geodistance.py +35 -0
  260. compas/geometry/trimesh_gradient_numpy.py +74 -0
  261. compas/geometry/trimesh_isolines.py +41 -0
  262. compas/geometry/trimesh_matrices.py +31 -0
  263. compas/geometry/trimesh_matrices_numpy.py +191 -0
  264. compas/geometry/trimesh_parametrisation.py +55 -0
  265. compas/geometry/trimesh_pull_points_numpy.py +216 -0
  266. compas/geometry/trimesh_remeshing.py +97 -0
  267. compas/geometry/trimesh_samplepoints_numpy.py +108 -0
  268. compas/geometry/trimesh_slicing.py +28 -0
  269. compas/geometry/trimesh_smoothing_numpy.py +34 -0
  270. compas/geometry/vector.py +889 -0
  271. compas/itertools.py +441 -0
  272. compas/linalg.py +634 -0
  273. compas/matrices.py +314 -0
  274. compas/plugins.py +488 -0
  275. compas/rpc/__init__.py +20 -0
  276. compas/rpc/__main__.py +77 -0
  277. compas/rpc/dispatcher.py +181 -0
  278. compas/rpc/errors.py +11 -0
  279. compas/rpc/proxy.py +437 -0
  280. compas/rpc/server.py +79 -0
  281. compas/rpc/services/__init__.py +0 -0
  282. compas/rpc/services/default.py +87 -0
  283. compas/rpc/services/watcher.py +43 -0
  284. compas/scene/__init__.py +56 -0
  285. compas/scene/assemblyobject.py +3 -0
  286. compas/scene/context.py +154 -0
  287. compas/scene/descriptors/__init__.py +0 -0
  288. compas/scene/descriptors/attribute.py +30 -0
  289. compas/scene/descriptors/color.py +91 -0
  290. compas/scene/descriptors/colordict.py +101 -0
  291. compas/scene/descriptors/protocol.py +12 -0
  292. compas/scene/exceptions.py +7 -0
  293. compas/scene/geometryobject.py +58 -0
  294. compas/scene/graphobject.py +173 -0
  295. compas/scene/meshobject.py +238 -0
  296. compas/scene/scene.py +144 -0
  297. compas/scene/sceneobject.py +253 -0
  298. compas/scene/volmeshobject.py +252 -0
  299. compas/tolerance.py +879 -0
  300. compas/topology/__init__.py +45 -0
  301. compas/topology/combinatorics.py +108 -0
  302. compas/topology/connectivity.py +129 -0
  303. compas/topology/orientation.py +204 -0
  304. compas/topology/traversal.py +567 -0
  305. compas/utilities/__init__.py +25 -0
  306. compas/utilities/azync.py +155 -0
  307. compas/utilities/datetime.py +40 -0
  308. compas/utilities/decorators.py +136 -0
  309. compas/utilities/remote.py +54 -0
  310. compas/utilities/ssh.py +169 -0
  311. compas-2.1.1.dist-info/AUTHORS.md +42 -0
  312. compas-2.1.1.dist-info/LICENSE +21 -0
  313. compas-2.1.1.dist-info/METADATA +132 -0
  314. compas-2.1.1.dist-info/RECORD +468 -0
  315. compas-2.1.1.dist-info/WHEEL +5 -0
  316. compas-2.1.1.dist-info/entry_points.txt +2 -0
  317. compas-2.1.1.dist-info/top_level.txt +4 -0
  318. compas_blender/__init__.py +250 -0
  319. compas_blender/collections.py +130 -0
  320. compas_blender/conversions/__init__.py +48 -0
  321. compas_blender/conversions/breps.py +0 -0
  322. compas_blender/conversions/colors.py +23 -0
  323. compas_blender/conversions/curves.py +125 -0
  324. compas_blender/conversions/geometry.py +161 -0
  325. compas_blender/conversions/meshes.py +148 -0
  326. compas_blender/conversions/surfaces.py +48 -0
  327. compas_blender/conversions/transformations.py +46 -0
  328. compas_blender/data.py +30 -0
  329. compas_blender/geometry/__init__.py +14 -0
  330. compas_blender/geometry/booleans.py +100 -0
  331. compas_blender/install.py +338 -0
  332. compas_blender/objects.py +326 -0
  333. compas_blender/print_python_path.py +18 -0
  334. compas_blender/scene/__init__.py +116 -0
  335. compas_blender/scene/boxobject.py +64 -0
  336. compas_blender/scene/capsuleobject.py +73 -0
  337. compas_blender/scene/circleobject.py +53 -0
  338. compas_blender/scene/coneobject.py +70 -0
  339. compas_blender/scene/curveobject.py +58 -0
  340. compas_blender/scene/cylinderobject.py +70 -0
  341. compas_blender/scene/frameobject.py +105 -0
  342. compas_blender/scene/graphobject.py +257 -0
  343. compas_blender/scene/lineobject.py +60 -0
  344. compas_blender/scene/meshobject.py +508 -0
  345. compas_blender/scene/planeobject.py +81 -0
  346. compas_blender/scene/pointcloudobject.py +67 -0
  347. compas_blender/scene/pointobject.py +71 -0
  348. compas_blender/scene/polygonobject.py +57 -0
  349. compas_blender/scene/polyhedronobject.py +57 -0
  350. compas_blender/scene/polylineobject.py +54 -0
  351. compas_blender/scene/sceneobject.py +249 -0
  352. compas_blender/scene/sphereobject.py +72 -0
  353. compas_blender/scene/surfaceobject.py +54 -0
  354. compas_blender/scene/torusobject.py +73 -0
  355. compas_blender/scene/vectorobject.py +69 -0
  356. compas_blender/scene/volmeshobject.py +475 -0
  357. compas_blender/utilities/__init__.py +38 -0
  358. compas_blender/utilities/drawing.py +768 -0
  359. compas_ghpython/__init__.py +124 -0
  360. compas_ghpython/components/Compas_FromJson/code.py +18 -0
  361. compas_ghpython/components/Compas_Info/code.py +15 -0
  362. compas_ghpython/components/Compas_RpcCall/code.py +31 -0
  363. compas_ghpython/components/Compas_ToJson/code.py +19 -0
  364. compas_ghpython/components/Compas_ToRhinoGeometry/code.py +15 -0
  365. compas_ghpython/components/__init__.py +99 -0
  366. compas_ghpython/install.py +29 -0
  367. compas_ghpython/scene/__init__.py +115 -0
  368. compas_ghpython/scene/boxobject.py +40 -0
  369. compas_ghpython/scene/brepobject.py +40 -0
  370. compas_ghpython/scene/capsuleobject.py +41 -0
  371. compas_ghpython/scene/circleobject.py +40 -0
  372. compas_ghpython/scene/coneobject.py +40 -0
  373. compas_ghpython/scene/curveobject.py +42 -0
  374. compas_ghpython/scene/cylinderobject.py +38 -0
  375. compas_ghpython/scene/ellipseobject.py +40 -0
  376. compas_ghpython/scene/frameobject.py +67 -0
  377. compas_ghpython/scene/graphobject.py +77 -0
  378. compas_ghpython/scene/lineobject.py +39 -0
  379. compas_ghpython/scene/meshobject.py +137 -0
  380. compas_ghpython/scene/planeobject.py +61 -0
  381. compas_ghpython/scene/pointobject.py +38 -0
  382. compas_ghpython/scene/polygonobject.py +48 -0
  383. compas_ghpython/scene/polyhedronobject.py +48 -0
  384. compas_ghpython/scene/polylineobject.py +39 -0
  385. compas_ghpython/scene/sceneobject.py +12 -0
  386. compas_ghpython/scene/sphereobject.py +39 -0
  387. compas_ghpython/scene/surfaceobject.py +42 -0
  388. compas_ghpython/scene/torusobject.py +39 -0
  389. compas_ghpython/scene/vectorobject.py +51 -0
  390. compas_ghpython/scene/volmeshobject.py +154 -0
  391. compas_ghpython/sets.py +83 -0
  392. compas_ghpython/timer.py +36 -0
  393. compas_ghpython/uninstall.py +31 -0
  394. compas_ghpython/utilities/__init__.py +33 -0
  395. compas_ghpython/utilities/drawing.py +457 -0
  396. compas_rhino/__init__.py +607 -0
  397. compas_rhino/conduits/__init__.py +16 -0
  398. compas_rhino/conduits/base.py +121 -0
  399. compas_rhino/conduits/faces.py +91 -0
  400. compas_rhino/conduits/labels.py +102 -0
  401. compas_rhino/conduits/lines.py +109 -0
  402. compas_rhino/conduits/points.py +111 -0
  403. compas_rhino/conversions/__init__.py +168 -0
  404. compas_rhino/conversions/breps.py +122 -0
  405. compas_rhino/conversions/curves.py +453 -0
  406. compas_rhino/conversions/docobjects.py +0 -0
  407. compas_rhino/conversions/exceptions.py +7 -0
  408. compas_rhino/conversions/extrusions.py +80 -0
  409. compas_rhino/conversions/geometry.py +187 -0
  410. compas_rhino/conversions/meshes.py +281 -0
  411. compas_rhino/conversions/shapes.py +291 -0
  412. compas_rhino/conversions/surfaces.py +355 -0
  413. compas_rhino/conversions/transformations.py +45 -0
  414. compas_rhino/geometry/__init__.py +44 -0
  415. compas_rhino/geometry/booleans.py +118 -0
  416. compas_rhino/geometry/brep/__init__.py +40 -0
  417. compas_rhino/geometry/brep/brep.py +554 -0
  418. compas_rhino/geometry/brep/builder.py +184 -0
  419. compas_rhino/geometry/brep/edge.py +202 -0
  420. compas_rhino/geometry/brep/face.py +285 -0
  421. compas_rhino/geometry/brep/loop.py +129 -0
  422. compas_rhino/geometry/brep/trim.py +99 -0
  423. compas_rhino/geometry/brep/vertex.py +76 -0
  424. compas_rhino/geometry/curves/__init__.py +43 -0
  425. compas_rhino/geometry/curves/curve.py +382 -0
  426. compas_rhino/geometry/curves/nurbs.py +298 -0
  427. compas_rhino/geometry/surfaces/__init__.py +50 -0
  428. compas_rhino/geometry/surfaces/nurbs.py +370 -0
  429. compas_rhino/geometry/surfaces/surface.py +407 -0
  430. compas_rhino/geometry/trimesh_curvature.py +344 -0
  431. compas_rhino/geometry/trimesh_slicing.py +65 -0
  432. compas_rhino/install.py +382 -0
  433. compas_rhino/install_plugin.py +169 -0
  434. compas_rhino/install_with_pip.py +20 -0
  435. compas_rhino/layers.py +347 -0
  436. compas_rhino/objects.py +1141 -0
  437. compas_rhino/print_python_path.py +18 -0
  438. compas_rhino/scene/__init__.py +123 -0
  439. compas_rhino/scene/boxobject.py +44 -0
  440. compas_rhino/scene/brepobject.py +41 -0
  441. compas_rhino/scene/capsuleobject.py +45 -0
  442. compas_rhino/scene/circleobject.py +43 -0
  443. compas_rhino/scene/coneobject.py +43 -0
  444. compas_rhino/scene/curveobject.py +43 -0
  445. compas_rhino/scene/cylinderobject.py +43 -0
  446. compas_rhino/scene/ellipseobject.py +44 -0
  447. compas_rhino/scene/frameobject.py +99 -0
  448. compas_rhino/scene/graphobject.py +364 -0
  449. compas_rhino/scene/helpers.py +33 -0
  450. compas_rhino/scene/lineobject.py +43 -0
  451. compas_rhino/scene/meshobject.py +673 -0
  452. compas_rhino/scene/planeobject.py +71 -0
  453. compas_rhino/scene/pointobject.py +43 -0
  454. compas_rhino/scene/polygonobject.py +45 -0
  455. compas_rhino/scene/polyhedronobject.py +45 -0
  456. compas_rhino/scene/polylineobject.py +43 -0
  457. compas_rhino/scene/sceneobject.py +123 -0
  458. compas_rhino/scene/sphereobject.py +43 -0
  459. compas_rhino/scene/surfaceobject.py +42 -0
  460. compas_rhino/scene/torusobject.py +43 -0
  461. compas_rhino/scene/vectorobject.py +49 -0
  462. compas_rhino/scene/volmeshobject.py +518 -0
  463. compas_rhino/ui.py +114 -0
  464. compas_rhino/uninstall.py +243 -0
  465. compas_rhino/uninstall_plugin.py +91 -0
  466. compas_rhino/utilities/__init__.py +37 -0
  467. compas_rhino/utilities/constructors.py +71 -0
  468. compas_rhino/utilities/drawing.py +1081 -0
@@ -0,0 +1,1105 @@
1
+ from __future__ import absolute_import
2
+ from __future__ import division
3
+ from __future__ import print_function
4
+
5
+ from math import fabs
6
+ from math import sqrt
7
+
8
+ from compas.geometry import add_vectors
9
+ from compas.geometry import cross_vectors
10
+ from compas.geometry import distance_point_point
11
+ from compas.geometry import dot_vectors
12
+ from compas.geometry import is_point_in_triangle
13
+ from compas.geometry import is_point_on_segment
14
+ from compas.geometry import is_point_on_segment_xy
15
+ from compas.geometry import length_vector_xy
16
+ from compas.geometry import normalize_vector
17
+ from compas.geometry import scale_vector
18
+ from compas.geometry import subtract_vectors
19
+ from compas.geometry import subtract_vectors_xy
20
+ from compas.itertools import pairwise
21
+ from compas.plugins import PluginNotInstalledError
22
+ from compas.plugins import pluggable
23
+ from compas.tolerance import TOL
24
+
25
+
26
+ def intersection_line_line(l1, l2, tol=None):
27
+ """Computes the intersection of two lines.
28
+
29
+ Parameters
30
+ ----------
31
+ l1 : [point, point] | :class:`compas.geometry.Line`
32
+ XYZ coordinates of two points defining the first line.
33
+ l2 : [point, point] | :class:`compas.geometry.Line`
34
+ XYZ coordinates of two points defining the second line.
35
+ tol : float, optional
36
+ Tolerance for evaluating the intersection points of each of the lines with the corresponding skew plane.
37
+ Default is :attr:`TOL.absolute`.
38
+
39
+ Returns
40
+ -------
41
+ tuple[[float, float, float], [float, float, float]] | tuple[None, None]
42
+ Two intersection points.
43
+ If the lines intersect, these two points are identical.
44
+ If the lines are skewed and thus only have an apparent intersection, the two points are different.
45
+ In all other cases there are no intersection points.
46
+
47
+ Examples
48
+ --------
49
+ The 2 intersection points of intersecting lines are identical.
50
+
51
+ >>> l1 = [0, 0, 0], [1, 0, 0]
52
+ >>> l2 = [0, 0, 0], [0, 1, 0]
53
+ >>> intersection_line_line(l1, l2)
54
+ ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])
55
+
56
+ Note that lines extend beyond their start and end points.
57
+
58
+ >>> l1 = [0, 0, 0], [1, 0, 0]
59
+ >>> l2 = [2, 0, 0], [0, 1, 0]
60
+ >>> intersection_line_line(l1, l2)
61
+ ([2.0, 0.0, 0.0], [2.0, 0.0, 0.0])
62
+
63
+ Skew lines have two different intersection points.
64
+
65
+ >>> l1 = [0, 0, 0], [1, 0, 0]
66
+ >>> l2 = [0, 0, 1], [0, 1, 1]
67
+ >>> intersection_line_line(l1, l2)
68
+ ([0.0, 0.0, 0.0], [0.0, 0.0, 1.0])
69
+
70
+ Parallel lines don't intersect.
71
+
72
+ >>> l1 = [0, 0, 0], [1, 0, 0]
73
+ >>> l2 = [0, 0, 0], [1, 0, 0]
74
+ >>> intersection_line_line(l1, l2)
75
+ (None, None)
76
+
77
+ """
78
+ a, b = l1
79
+ c, d = l2
80
+
81
+ ab = subtract_vectors(b, a)
82
+ cd = subtract_vectors(d, c)
83
+
84
+ n = cross_vectors(ab, cd)
85
+ n1 = normalize_vector(cross_vectors(ab, n))
86
+ n2 = normalize_vector(cross_vectors(cd, n))
87
+
88
+ plane_1 = (a, n1)
89
+ plane_2 = (c, n2)
90
+
91
+ i1 = intersection_line_plane(l1, plane_2, tol=tol)
92
+ i2 = intersection_line_plane(l2, plane_1, tol=tol)
93
+
94
+ if not i1 or not i2:
95
+ return None, None
96
+
97
+ return i1, i2
98
+
99
+
100
+ def intersection_segment_segment(ab, cd, tol=None):
101
+ """Compute the intersection of two lines segments.
102
+
103
+ Parameters
104
+ ----------
105
+ ab : [point, point] | :class:`compas.geometry.Line`
106
+ XYZ coordinates of two points defining a line segment.
107
+ cd : [point, point] | :class:`compas.geometry.Line`
108
+ XYZ coordinates of two points defining another line segment.
109
+ tol : float, optional
110
+ Tolerance value for computing the intersection points of the underlying lines,
111
+ and for verifying that those points are contained by the segments.
112
+ Default is :attr:`TOL.absolute`.
113
+
114
+ Returns
115
+ -------
116
+ tuple[[float, float, float], [float, float, float]] | tuple[None, None]
117
+ Two intersection points.
118
+ If the segments intersect and the intersection points lie on the respective segments, the two points are identical.
119
+ If the segments are skew and the apparent intersection points lie on the respective segments, the two points are different.
120
+ In all other cases there are no intersection points.
121
+
122
+ Examples
123
+ --------
124
+ The 2 intersection points of intersecting segments are identical.
125
+
126
+ >>> s1 = [0, 0, 0], [1, 0, 0]
127
+ >>> s2 = [0, 0, 0], [0, 1, 0]
128
+ >>> intersection_segment_segment(s1, s2)
129
+ ([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])
130
+
131
+ Unlike lines, segments don't extend beyond their start and end points.
132
+
133
+ >>> s1 = [0, 0, 0], [1, 0, 0]
134
+ >>> s2 = [2, 0, 0], [0, 1, 0]
135
+ >>> intersection_segment_segment(s1, s2)
136
+ (None, None)
137
+
138
+ Skew segments have two different intersection points.
139
+
140
+ >>> s1 = [0, 0, 0], [1, 0, 0]
141
+ >>> s2 = [0, 0, 1], [0, 1, 1]
142
+ >>> intersection_segment_segment(s1, s2)
143
+ ([0.0, 0.0, 0.0], [0.0, 0.0, 1.0])
144
+
145
+ Parallel segments don't intersect.
146
+
147
+ >>> s1 = [0, 0, 0], [1, 0, 0]
148
+ >>> s2 = [0, 0, 0], [1, 0, 0]
149
+ >>> intersection_segment_segment(s1, s2)
150
+ (None, None)
151
+
152
+ """
153
+ x1, x2 = intersection_line_line(ab, cd, tol=tol)
154
+
155
+ if not x1 or not x2:
156
+ return None, None
157
+
158
+ if not is_point_on_segment(x1, ab, tol=tol):
159
+ return None, None
160
+
161
+ if not is_point_on_segment(x2, cd, tol=tol):
162
+ return None, None
163
+
164
+ return x1, x2
165
+
166
+
167
+ def intersection_line_segment(line, segment, tol=None):
168
+ """Compute the intersection of a line and a segment.
169
+
170
+ Parameters
171
+ ----------
172
+ line : [point, point] | :class:`compas.geometry.Line`
173
+ Two points defining a line.
174
+ segment : [point, point] | :class:`compas.geometry.Line`
175
+ Two points defining a line segment.
176
+ tol : float, optional
177
+ Tolerance value for computing the intersection points of the underlying lines,
178
+ and for verifying that those points are contained by the segment.
179
+ Default is :attr:`TOL.absolute`.
180
+
181
+ Returns
182
+ -------
183
+ tuple[[float, float, float], [float, float, float]] | tuple[None, None]
184
+ Two intersection points.
185
+ If the line and segment intersect and the second intersection point lies on the segment, the two points are identical.
186
+ If the line and segment are skew and the second apparent intersection point lies on the segment, the two points are different.
187
+ In all other cases there are no intersection points.
188
+
189
+ """
190
+ x1, x2 = intersection_line_line(line, segment, tol=tol)
191
+
192
+ if not x1 or not x2:
193
+ return None, None
194
+
195
+ if not is_point_on_segment(x2, segment, tol=tol):
196
+ return None, None
197
+
198
+ return x1, x2
199
+
200
+
201
+ def intersection_line_plane(line, plane, tol=None):
202
+ """Computes the intersection point of a line and a plane
203
+
204
+ Parameters
205
+ ----------
206
+ line : [point, point] | :class:`compas.geometry.Line`
207
+ Two points defining the line.
208
+ plane : [point, vector]
209
+ The base point and normal defining the plane.
210
+ tol : float, optional
211
+ Tolerance for evaluating that the dot product of the line direction and the plane normal is zero.
212
+ Default is :attr:`TOL.absolute`.
213
+
214
+ Returns
215
+ -------
216
+ [float, float, float] | None
217
+ The intersection point between the line and the plane,
218
+ or None if the line and the plane are parallel.
219
+
220
+ See Also
221
+ --------
222
+ :func:`intersection_segment_plane`
223
+ :func:`intersection_polyline_plane`
224
+
225
+ """
226
+ a, b = line
227
+ o, n = plane
228
+
229
+ ab = subtract_vectors(b, a)
230
+ cosa = dot_vectors(n, ab)
231
+
232
+ if TOL.is_zero(cosa, tol):
233
+ # if the dot product (cosine of the angle between segment and plane)
234
+ # is close to zero the line and the normal are almost perpendicular
235
+ # hence there is no intersection
236
+ return None
237
+
238
+ # based on the ratio = -dot_vectors(n, ab) / dot_vectors(n, oa)
239
+ # there are three scenarios
240
+ # 1) 0.0 < ratio < 1.0: the intersection is between a and b
241
+ # 2) ratio < 0.0: the intersection is on the other side of a
242
+ # 3) ratio > 1.0: the intersection is on the other side of b
243
+ oa = subtract_vectors(a, o)
244
+ ratio = -dot_vectors(n, oa) / cosa
245
+ ab = scale_vector(ab, ratio)
246
+ return add_vectors(a, ab)
247
+
248
+
249
+ def intersection_segment_plane(segment, plane, tol=None):
250
+ """Computes the intersection point of a line segment and a plane
251
+
252
+ Parameters
253
+ ----------
254
+ segment : [point, point] | :class:`compas.geometry.Line`
255
+ Two points defining the line segment.
256
+ plane : [point, vector]
257
+ The base point and normal defining the plane.
258
+ tol : float, optional
259
+ Tolerance for evaluating that the dot product of the line direction and the plane normal is zero.
260
+ Default is :attr:`TOL.absolute`.
261
+
262
+ Returns
263
+ -------
264
+ [float, float, float] | None
265
+ The intersection point between the line and the plane,
266
+ or None if the line and the plane are parallel.
267
+
268
+ See Also
269
+ --------
270
+ :func:`intersection_line_plane`
271
+ :func:`intersection_polyline_plane`
272
+
273
+ """
274
+ a, b = segment
275
+ o, n = plane
276
+
277
+ ab = subtract_vectors(b, a)
278
+ cosa = dot_vectors(n, ab)
279
+
280
+ if TOL.is_zero(cosa, tol):
281
+ # if the dot product (cosine of the angle between segment and plane)
282
+ # is close to zero the line and the normal are almost perpendicular
283
+ # hence there is no intersection
284
+ return None
285
+
286
+ # based on the ratio = -dot_vectors(n, ab) / dot_vectors(n, oa)
287
+ # there are three scenarios
288
+ # 1) 0.0 < ratio < 1.0: the intersection is between a and b
289
+ # 2) ratio < 0.0: the intersection is on the other side of a
290
+ # 3) ratio > 1.0: the intersection is on the other side of b
291
+ oa = subtract_vectors(a, o)
292
+ ratio = -dot_vectors(n, oa) / cosa
293
+
294
+ if 0.0 <= ratio and ratio <= 1.0:
295
+ ab = scale_vector(ab, ratio)
296
+ return add_vectors(a, ab)
297
+
298
+ return None
299
+
300
+
301
+ def intersection_polyline_plane(polyline, plane, expected_number_of_intersections=None, tol=None):
302
+ """Calculate the intersection point of a plane with a polyline. Reduce expected_number_of_intersections to speed up.
303
+
304
+ Parameters
305
+ ----------
306
+ polyline : sequence[point] | :class:`compas.geometry.Polyline`
307
+ Polyline to test intersection.
308
+ plane : [point, vector]
309
+ Plane to compute intersection.
310
+ expected_number_of_intersections : int, optional
311
+ Number of useful or expected intersections.
312
+ Default is the number of line segments of the polyline.
313
+ tol : float, optional
314
+ Tolerance for computing the intersection points between the individual segments of the polyline and the plane.
315
+ Default is :attr:`TOL.absolute`.
316
+
317
+ Returns
318
+ -------
319
+ list[[float, float, float]]
320
+ The intersection points between the polyline segments and the plane.
321
+
322
+ See Also
323
+ --------
324
+ :func:`intersection_segment_plane`
325
+ :func:`intersection_line_plane`
326
+
327
+ """
328
+ if not expected_number_of_intersections:
329
+ expected_number_of_intersections = len(polyline)
330
+ intersections = []
331
+ for segment in pairwise(polyline):
332
+ if len(intersections) == expected_number_of_intersections:
333
+ break
334
+ point = intersection_segment_plane(segment, plane, tol)
335
+ if point:
336
+ intersections.append(point)
337
+ return intersections
338
+
339
+
340
+ def intersection_line_triangle(line, triangle, tol=None):
341
+ """Computes the intersection point of a line (ray) and a triangle
342
+ based on the Moeller Trumbore intersection algorithm
343
+
344
+ Parameters
345
+ ----------
346
+ line : [point, point] | :class:`compas.geometry.Line`
347
+ Two points defining the line.
348
+ triangle : [point, point, point]
349
+ XYZ coordinates of the triangle corners.
350
+ tol : float, optional
351
+ Tolerance value for computing the intersection between the line and the plane of the triangle.
352
+ Default is :attr:`TOL.absolute`.
353
+
354
+ Returns
355
+ -------
356
+ [float, float, float] | None
357
+ The intersection point between the line and the triangle,
358
+ or None if the line and the plane are parallel.
359
+
360
+ """
361
+ a, b, c = triangle
362
+ ab = subtract_vectors(b, a)
363
+ ac = subtract_vectors(c, a)
364
+ n = cross_vectors(ab, ac)
365
+ plane = a, n
366
+
367
+ x = intersection_line_plane(line, plane, tol=tol)
368
+
369
+ if x:
370
+ if is_point_in_triangle(x, triangle):
371
+ return x
372
+
373
+
374
+ def intersection_plane_plane(plane1, plane2, tol=None):
375
+ """Computes the intersection of two planes
376
+
377
+ Parameters
378
+ ----------
379
+ plane1 : [point, vector]
380
+ The base point and normal (normalized) defining the 1st plane.
381
+ plane2 : [point, vector]
382
+ The base point and normal (normalized) defining the 2nd plane.
383
+ tol : float, optional
384
+ Tolerance for evaluating if the dot product of the plane normals is one.
385
+ Default is :attr:`TOL.absolute`.
386
+
387
+ Returns
388
+ -------
389
+ tuple[[float, float, float], [float, float, float]] | None
390
+ Two points defining the intersection line.
391
+ None if the planes are parallel.
392
+
393
+ """
394
+ o1, n1 = plane1
395
+ o2, n2 = plane2
396
+
397
+ if TOL.is_close(dot_vectors(n1, n2), 1.0, tol):
398
+ return None
399
+
400
+ # direction of intersection line
401
+ d = cross_vectors(n1, n2)
402
+ # vector in plane 1 perpendicular to the direction of the intersection line
403
+ v1 = cross_vectors(d, n1)
404
+ # point on plane 1
405
+ p1 = add_vectors(o1, v1)
406
+
407
+ x1 = intersection_line_plane((o1, p1), plane2, tol=tol)
408
+ x2 = add_vectors(x1, d)
409
+ return x1, x2
410
+
411
+
412
+ def intersection_plane_plane_plane(plane1, plane2, plane3, tol=None):
413
+ """Computes the intersection of three planes
414
+
415
+ Parameters
416
+ ----------
417
+ plane1 : [point, vector]
418
+ The base point and normal (normalized) defining the 1st plane.
419
+ plane2 : [point, vector]
420
+ The base point and normal (normalized) defining the 2nd plane.
421
+ plane3 : [point, vector]
422
+ The base point and normal (normalized) defining the 3rd plane.
423
+ tol : float, optional
424
+ Tolerance for computing the intersection line between the first two planes, and between the intersection line and the third plane.
425
+ Default is :attr:`TOL.absolute`.
426
+
427
+ Returns
428
+ -------
429
+ [float, float, float] | None
430
+ The intersection point
431
+ or None if at least one pair of planes is parallel.
432
+
433
+ Notes
434
+ -----
435
+ Currently this only computes the intersection point.
436
+ For example, if two planes are parallel the intersection lines are not computed [1]_.
437
+
438
+ References
439
+ ----------
440
+ .. [1] http://geomalgorithms.com/Pic_3-planes.gif
441
+
442
+ """
443
+ line = intersection_plane_plane(plane1, plane2, tol=tol)
444
+ if line:
445
+ return intersection_line_plane(line, plane3, tol=tol)
446
+
447
+
448
+ def intersection_sphere_sphere(sphere1, sphere2):
449
+ """Computes the intersection of 2 spheres.
450
+
451
+ Parameters
452
+ ----------
453
+ sphere1 : [point, float]
454
+ A sphere defined by a point and radius.
455
+ sphere2 : [point, float]
456
+ A sphere defined by a point and radius.
457
+
458
+ Returns
459
+ -------
460
+ {'point', 'circle', or 'sphere'}
461
+ The type of intersection.
462
+ [float, float, float] | tuple[[float, float, float], float, [float, float, float]] | tuple[[float, float, float], float]
463
+ If the type is 'point', the coordinates of the point.
464
+ If the type is 'circle', the center point and radius of the circle, and the normal of the plane containing the circle.
465
+ If the type is 'sphere', the center point and radius of the sphere.
466
+
467
+ Notes
468
+ -----
469
+ There are 4 cases of sphere-sphere intersection [1]_:
470
+
471
+ 1. the spheres intersect in a circle,
472
+ 2. they intersect in a point,
473
+ 3. they overlap,
474
+ 4. they do not intersect.
475
+
476
+ References
477
+ ----------
478
+ .. [1] https://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection
479
+
480
+ Examples
481
+ --------
482
+ >>> sphere1 = (3.0, 7.0, 4.0), 10.0
483
+ >>> sphere2 = (7.0, 4.0, 0.0), 5.0
484
+ >>> result = intersection_sphere_sphere(sphere1, sphere2)
485
+ >>> if result:
486
+ ... case, res = result
487
+ ... if case == "circle":
488
+ ... center, radius, normal = res
489
+ ... elif case == "point":
490
+ ... point = res
491
+ ... elif case == "sphere":
492
+ ... center, radius = res
493
+
494
+ """
495
+
496
+ center1, radius1 = sphere1.base, sphere1.radius
497
+ center2, radius2 = sphere2.base, sphere2.radius
498
+
499
+ distance = distance_point_point(center1, center2)
500
+
501
+ # Case 4: No intersection
502
+ if radius1 + radius2 < distance:
503
+ return None
504
+
505
+ # Case 4: No intersection, sphere is within the other sphere
506
+ elif distance + min(radius1, radius2) < max(radius1, radius2):
507
+ return None
508
+
509
+ # Case 3: sphere's overlap
510
+ elif radius1 == radius2 and distance == 0:
511
+ return "sphere", sphere1
512
+
513
+ # Case 2: point intersection
514
+ elif radius1 + radius2 == distance:
515
+ ipt = subtract_vectors(center2, center1)
516
+ ipt = scale_vector(ipt, radius1 / distance)
517
+ ipt = add_vectors(center1, ipt)
518
+ return "point", ipt
519
+
520
+ # Case 2: point intersection, smaller sphere is within the bigger
521
+ elif distance + min(radius1, radius2) == max(radius1, radius2):
522
+ if radius1 > radius2:
523
+ ipt = subtract_vectors(center2, center1)
524
+ ipt = scale_vector(ipt, radius1 / distance)
525
+ ipt = add_vectors(center1, ipt)
526
+ else:
527
+ ipt = subtract_vectors(center1, center2)
528
+ ipt = scale_vector(ipt, radius2 / distance)
529
+ ipt = add_vectors(center2, ipt)
530
+ return "point", ipt
531
+
532
+ # Case 1: circle intersection
533
+ h = 0.5 + (radius1**2 - radius2**2) / (2 * distance**2)
534
+ ci = subtract_vectors(center2, center1)
535
+ ci = scale_vector(ci, h)
536
+ ci = add_vectors(center1, ci)
537
+ ri = sqrt(radius1**2 - h**2 * distance**2)
538
+ normal = scale_vector(subtract_vectors(center2, center1), 1 / distance)
539
+ return "circle", (ci, ri, normal)
540
+
541
+
542
+ def intersection_segment_polyline(segment, polyline, tol=None):
543
+ """Calculate the intersection point of a segment and a polyline.
544
+
545
+ Parameters
546
+ ----------
547
+ segment : [point, point] | :class:`compas.geometry.Line`
548
+ XYZ coordinates of two points defining a line segment.
549
+ polyline : sequence[point] | :class:`compas.geometry.Polyline`
550
+ XYZ coordinates of the points of the polyline.
551
+ tol : float, optional
552
+ Tolerance value for computing the intersection points between the segment and the polyline segments.
553
+ Default is :attr:`TOL.absolute`.
554
+
555
+ Returns
556
+ -------
557
+ [float, float, float] | None
558
+ The intersection point
559
+ or None if the segment does not intersect with any of the polyline segments.
560
+
561
+ Examples
562
+ --------
563
+ >>> from compas.geometry import is_point_on_polyline
564
+ >>> from compas.geometry import is_point_on_segment
565
+ >>> from compas.geometry import distance_point_point
566
+ >>> from compas.geometry import centroid_points
567
+ >>> p = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.5), (2.0, 0.5, 1.0)]
568
+ >>> s = [(0.5, 0.0, 0.0), (0.5, 0.0, 2.0)]
569
+ >>> x1, x2 = intersection_segment_polyline(s, p)
570
+ >>> x = centroid_points([x1, x2])
571
+
572
+ >>> is_point_on_polyline(x, p)
573
+ True
574
+
575
+ >>> is_point_on_segment(x, s)
576
+ True
577
+
578
+ >>> distance_point_point((0.5, 0.0, 0.25), x) < 1e-6
579
+ True
580
+ """
581
+ for cd in pairwise(polyline):
582
+ pt = intersection_segment_segment(segment, cd, tol)
583
+ if pt:
584
+ return pt
585
+
586
+
587
+ def intersection_sphere_line(sphere, line):
588
+ """Computes the intersection of a sphere and a line.
589
+
590
+ Parameters
591
+ ----------
592
+ sphere : [point, radius]
593
+ A sphere defined by a point and a radius.
594
+ line : [point, point] | :class:`compas.geometry.Line`
595
+ A line defined by two points.
596
+
597
+ Returns
598
+ -------
599
+ tuple[[float, float, float], [float, float, float]] | [float, float, float] | None
600
+ Two points (if the line goes through the sphere), one point (if the line is tangent to the sphere), or None (otherwise).
601
+
602
+ Notes
603
+ -----
604
+ There are 3 cases of sphere-line intersection:
605
+
606
+ 1. they intersect in 2 points
607
+ 2. they intersect in 1 point (line tangent to sphere), or
608
+ 3. they do not intersect.
609
+
610
+ Examples
611
+ --------
612
+ >>> from compas.tolerance import TOL
613
+
614
+ >>> sphere = (3.0, 7.0, 4.0), 10.0
615
+ >>> line = (1.0, 0, 0.5), (2.0, 1.0, 0.5)
616
+ >>> x1, x2 = intersection_sphere_line(sphere, line)
617
+
618
+ >>> TOL.is_allclose(x1, [11.634, 10.634, 0.500], atol=1e-3)
619
+ True
620
+ >>> TOL.is_allclose(x2, [-0.634, -1.634, 0.50], atol=1e-3)
621
+ True
622
+
623
+ """
624
+ l1, l2 = line
625
+ sp, radius = sphere
626
+
627
+ a = (l2[0] - l1[0]) ** 2 + (l2[1] - l1[1]) ** 2 + (l2[2] - l1[2]) ** 2
628
+ b = 2.0 * ((l2[0] - l1[0]) * (l1[0] - sp[0]) + (l2[1] - l1[1]) * (l1[1] - sp[1]) + (l2[2] - l1[2]) * (l1[2] - sp[2]))
629
+
630
+ c = sp[0] ** 2 + sp[1] ** 2 + sp[2] ** 2 + l1[0] ** 2 + l1[1] ** 2 + l1[2] ** 2 - 2.0 * (sp[0] * l1[0] + sp[1] * l1[1] + sp[2] * l1[2]) - radius**2
631
+
632
+ i = b * b - 4.0 * a * c
633
+
634
+ if i < 0.0: # case 3: no intersection
635
+ return None
636
+ elif i == 0.0: # case 2: one intersection
637
+ mu = -b / (2.0 * a)
638
+ ipt = (
639
+ l1[0] + mu * (l2[0] - l1[0]),
640
+ l1[1] + mu * (l2[1] - l1[1]),
641
+ l1[2] + mu * (l2[2] - l1[2]),
642
+ )
643
+ return ipt
644
+ elif i > 0.0: # case 1: two intersections
645
+ # 1.
646
+ mu = (-b + sqrt(i)) / (2.0 * a)
647
+ ipt1 = (
648
+ l1[0] + mu * (l2[0] - l1[0]),
649
+ l1[1] + mu * (l2[1] - l1[1]),
650
+ l1[2] + mu * (l2[2] - l1[2]),
651
+ )
652
+ # 2.
653
+ mu = (-b - sqrt(i)) / (2.0 * a)
654
+ ipt2 = (
655
+ l1[0] + mu * (l2[0] - l1[0]),
656
+ l1[1] + mu * (l2[1] - l1[1]),
657
+ l1[2] + mu * (l2[2] - l1[2]),
658
+ )
659
+ return ipt1, ipt2
660
+
661
+
662
+ def intersection_plane_circle(plane, circle):
663
+ """Computes the intersection of a plane and a circle.
664
+
665
+ Parameters
666
+ ----------
667
+ plane : [point, vector]
668
+ A plane defined by a point and normal vector.
669
+ circle : [plane, float]
670
+ A circle defined by a plane and radius.
671
+
672
+ Returns
673
+ -------
674
+ tuple[[float, float, float], [float, float, float]] | [float, float, float] | None
675
+ Two points (secant intersection), one point (tangent intersection), or None (otherwise).
676
+
677
+ Notes
678
+ -----
679
+ There are 4 cases of plane-circle intersection:
680
+
681
+ 1. they intersect in 2 points (secant),
682
+ 2. they intersect in 1 point (tangent),
683
+ 3. they do not intersect, or
684
+ 4. they coincide (circle.plane == plane).
685
+
686
+ Examples
687
+ --------
688
+ >>> plane = (0, 0, 0), (0, 0, 1)
689
+ >>> circle = ((0, 0, 0), (0, 1, 0)), 10.0
690
+ >>> x1, x2 = intersection_plane_circle(plane, circle)
691
+ >>> x1
692
+ (-10.0, 0.0, 0.0)
693
+ >>> x2
694
+ (10.0, 0.0, 0.0)
695
+
696
+ """
697
+ circle_plane, circle_radius = circle
698
+ line = intersection_plane_plane(plane, circle_plane)
699
+ if not line:
700
+ return None
701
+ circle_point = circle_plane[0]
702
+ sphere = circle_point, circle_radius
703
+ return intersection_sphere_line(sphere, line)
704
+
705
+
706
+ @pluggable(category="intersections")
707
+ def intersection_mesh_mesh(A, B):
708
+ """Compute the intersection of two meshes.
709
+
710
+ Parameters
711
+ ----------
712
+ A : tuple of vertices and faces
713
+ Mesh A.
714
+ B : tuple of vertices and faces
715
+ Mesh B.
716
+
717
+ Returns
718
+ -------
719
+ list of arrays of points
720
+ The intersection polylines as arrays of points.
721
+
722
+ """
723
+ raise PluginNotInstalledError
724
+
725
+
726
+ intersection_mesh_mesh.__pluggable__ = True
727
+
728
+
729
+ @pluggable(category="intersections")
730
+ def intersection_ray_mesh(ray, mesh):
731
+ """Compute the intersection(s) between a ray and a mesh.
732
+
733
+ Parameters
734
+ ----------
735
+ ray : tuple of point and vector
736
+ A ray represented by a point and a direction vector.
737
+ mesh : tuple of vertices and faces
738
+ A mesh represented by a list of vertices and a list of faces.
739
+
740
+ Returns
741
+ -------
742
+ list of tuple
743
+ Per intersection of the ray with the mesh:
744
+
745
+ 0. the index of the intersected face
746
+ 1. the u coordinate of the intersection in the barycentric coordinates of the face
747
+ 2. the u coordinate of the intersection in the barycentric coordinates of the face
748
+ 3. the distance between the ray origin and the hit
749
+
750
+ Examples
751
+ --------
752
+ >>>
753
+
754
+ """
755
+ raise PluginNotInstalledError
756
+
757
+
758
+ intersection_ray_mesh.__pluggable__ = True
759
+
760
+
761
+ # ==============================================================================
762
+ # XY
763
+ # ==============================================================================
764
+
765
+
766
+ def intersection_line_line_xy(l1, l2, tol=None):
767
+ """Compute the intersection of two lines, assuming they lie on the XY plane.
768
+
769
+ Parameters
770
+ ----------
771
+ l1 : [point, point] | :class:`compas.geometry.Line`
772
+ A line defined by two points, with at least XY coordinates.
773
+ l2 : [point, point] | :class:`compas.geometry.Line`
774
+ A line defined by two points, with at least XY coordinates.
775
+ tol : float, optional
776
+ Tolerance for comparing the length of the cross product of the line directions with zero.
777
+ Default is :attr:`TOL.absolute`.
778
+
779
+ Returns
780
+ -------
781
+ [float, float, 0.0] | None
782
+ XYZ coordinates of intersection point if one exists, with Z = 0.
783
+ Otherwise, None.
784
+
785
+ """
786
+ a, b = l1
787
+ c, d = l2
788
+
789
+ x1, y1 = a[0], a[1]
790
+ x2, y2 = b[0], b[1]
791
+ x3, y3 = c[0], c[1]
792
+ x4, y4 = d[0], d[1]
793
+
794
+ d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
795
+
796
+ if TOL.is_zero(d, tol):
797
+ return None
798
+
799
+ a = x1 * y2 - y1 * x2
800
+ b = x3 * y4 - y3 * x4
801
+ x = (a * (x3 - x4) - (x1 - x2) * b) / d
802
+ y = (a * (y3 - y4) - (y1 - y2) * b) / d
803
+
804
+ return [x, y, 0.0]
805
+
806
+
807
+ def intersection_line_segment_xy(line, segment, tol=None):
808
+ """Compute the intersection between a line and a segment.
809
+
810
+ Parameters
811
+ ----------
812
+ line : [point, point] | :class:`compas.geometry.Line`
813
+ A line defined by two points, with at least XY coordinates.
814
+ segment : [point, point] | :class:`compas.geometry.Line`
815
+ A segment defined by two points, with at least XY coordinates.
816
+ tol : float, optional
817
+ Tolerance for computing the intersection between the line and the underlying line of the segment,
818
+ and for verifying that the point is on the segment.
819
+ Default is :attr:`TOL.absolute`.
820
+
821
+ Returns
822
+ -------
823
+ [float, float, 0.0] | None
824
+ XYZ coordinates of the intersection, if one exists, with Z = 0.
825
+ None otherwise.
826
+
827
+ """
828
+ x = intersection_line_line_xy(line, segment, tol=tol)
829
+ if x:
830
+ if is_point_on_segment_xy(x, segment, tol=tol):
831
+ return x
832
+
833
+
834
+ def intersection_line_box_xy(line, box, tol=None):
835
+ """Compute the intersection between a line and a box in the XY plane.
836
+
837
+ Parameters
838
+ ----------
839
+ line : [point, point] | :class:`compas.geometry.Line`
840
+ A line defined by two points, with at least XY coordinates.
841
+ box : [point, point, point, point]
842
+ A box defined by 4 points, with at least XY coordinates.
843
+ tol : float, optional
844
+ A tolerance value for point comparison.
845
+ Default is :attr:`TOL.absolute`.
846
+
847
+ Returns
848
+ -------
849
+ tuple[[float, float, 0.0], [float, float, 0.0]] | [float, float, 0.0] | None
850
+ Two points if the line goes through the box.
851
+ One point if the line goes through one of the box vertices only.
852
+ None otherwise.
853
+
854
+ """
855
+ points = []
856
+ for segment in pairwise(box + box[:1]):
857
+ x = intersection_line_segment_xy(line, segment, tol=tol)
858
+ if x:
859
+ points.append(x)
860
+
861
+ if len(points) < 3:
862
+ return tuple(points)
863
+
864
+ if len(points) == 3:
865
+ a, b, c = points
866
+
867
+ if TOL.is_allclose(a, b, rtol=0, atol=tol):
868
+ return a, c
869
+
870
+ if TOL.is_allclose(b, c, rtol=0, atol=tol):
871
+ return a, b
872
+
873
+ return b, c
874
+
875
+
876
+ def intersection_polyline_box_xy(polyline, box, tol=None):
877
+ """Compute the intersection between a polyline and a box in the XY plane.
878
+
879
+ Parameters
880
+ ----------
881
+ polyline : sequence[point] | :class:`compas.geometry.Polyline`
882
+ A polyline defined by a sequence of points, with at least XY coordinates.
883
+ box : [point, point, point, point]
884
+ A box defined by a sequence of 4 points, with at least XY coordinates.
885
+ tol : float, optional
886
+ A tolerance value for point comparison.
887
+
888
+ Returns
889
+ -------
890
+ list[[float, float, 0.0]]
891
+ A list of intersection points.
892
+
893
+ """
894
+ precision = TOL.precision_from_tolerance(tol)
895
+ points = []
896
+ for side in pairwise(box + box[:1]):
897
+ for segment in pairwise(polyline):
898
+ x = intersection_segment_segment_xy(side, segment, tol=tol)
899
+ if x:
900
+ points.append(x)
901
+ points = {TOL.geometric_key(point, precision): point for point in points}
902
+ return list(points.values())
903
+
904
+
905
+ def intersection_segment_segment_xy(ab, cd, tol=None):
906
+ """Compute the intersection of two lines segments, assuming they lie in the XY plane.
907
+
908
+ Parameters
909
+ ----------
910
+ ab : [point, point] | :class:`compas.geometry.Line`
911
+ A segment defined by two points, with at least XY coordinates.
912
+ cd : [point, point] | :class:`compas.geometry.Line`
913
+ A segment defined by two points, with at least XY coordinates.
914
+ tol : float, optional
915
+ A tolerance for verifying that the point lies on both segments.
916
+ Default is :attr:`TOL.absolute`.
917
+
918
+ Returns
919
+ -------
920
+ [float, float, 0.0] | None
921
+ XYZ coordinates of intersection point if one exists.
922
+ None otherwise.
923
+
924
+ """
925
+ intx_pt = intersection_line_line_xy(ab, cd, tol=tol)
926
+
927
+ if not intx_pt:
928
+ return None
929
+
930
+ if not is_point_on_segment_xy(intx_pt, ab, tol=tol):
931
+ return None
932
+
933
+ if not is_point_on_segment_xy(intx_pt, cd, tol=tol):
934
+ return None
935
+
936
+ return intx_pt
937
+
938
+
939
+ def intersection_circle_circle_xy(circle1, circle2):
940
+ """Calculates the intersection points of two circles in 2d lying in the XY plane.
941
+
942
+ Parameters
943
+ ----------
944
+ circle1 : [plane, float]
945
+ Circle defined by a plane, with at least XY coordinates, and a radius.
946
+ circle2 : [plane, float]
947
+ Circle defined by a plane, with at least XY coordinates, and a radius.
948
+
949
+ Returns
950
+ -------
951
+ tuple[[float, float, float], [float, float, float]] | None
952
+ The intersection points if there are any.
953
+ If the circles are tangent to each other, the two intersection points are identical.
954
+ None otherwise.
955
+
956
+ """
957
+ plane1, r1 = circle1
958
+ plane2, r2 = circle2
959
+ p1, n1 = plane1
960
+ p2, n2 = plane2
961
+ R = length_vector_xy(subtract_vectors_xy(p2, p1))
962
+
963
+ if R > r1 + r2:
964
+ return None
965
+
966
+ if R < fabs(r1 - r2):
967
+ return None
968
+
969
+ if (R == 0) and (r1 == r2):
970
+ return None
971
+
972
+ x1, y1 = p1[:2]
973
+ x2, y2 = p2[:2]
974
+
975
+ cx = 0.5 * (x1 + x2)
976
+ cy = 0.5 * (y2 + y1)
977
+
978
+ R2 = R * R
979
+ R4 = R2 * R2
980
+
981
+ a = (r1 * r1 - r2 * r2) / (2 * R2)
982
+ b = 0.5 * sqrt(2 * (r1 * r1 + r2 * r2) / R2 - (r1 * r1 - r2 * r2) ** 2 / R4 - 1)
983
+
984
+ i1 = cx + a * (x2 - x1) + b * (y2 - y1), cy + a * (y2 - y1) + b * (x1 - x2), 0
985
+ i2 = cx + a * (x2 - x1) - b * (y2 - y1), cy + a * (y2 - y1) - b * (x1 - x2), 0
986
+
987
+ return i1, i2
988
+
989
+
990
+ def intersection_segment_polyline_xy(segment, polyline, tol=None):
991
+ """
992
+ Calculate the intersection point of a segment and a polyline on the XY-plane.
993
+
994
+ Parameters
995
+ ----------
996
+ segment : [point, point] | :class:`compas.geometry.Line`
997
+ A line segment defined by two points, with at least XY coordinates.
998
+ polyline : sequence[point] | :class:`compas.geometry.Polyline`
999
+ A polyline defined by a sequence of points, with at least XY coordinates.
1000
+ tol : float, optional
1001
+ Tolerance for computing the intersection points between the segment and the polyline segments.
1002
+ Default is :attr:`TOL.absolute`.
1003
+
1004
+ Returns
1005
+ -------
1006
+ [float, float, 0.0] | None
1007
+ XYZ coordinates of the first intersection point if one exists.
1008
+ None otherwise
1009
+
1010
+ Examples
1011
+ --------
1012
+ >>> from compas.geometry import is_point_on_polyline_xy
1013
+ >>> from compas.geometry import is_point_on_segment_xy
1014
+ >>> from compas.geometry import distance_point_point
1015
+ >>> p = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (2.0, 0.0, 0.0)]
1016
+ >>> s = [(0.5, -0.5, 0.0), (0.5, 0.5, 0.0)]
1017
+ >>> x = intersection_segment_polyline_xy(s, p)
1018
+ >>> is_point_on_polyline_xy(x, p)
1019
+ True
1020
+ >>> is_point_on_segment_xy(x, s)
1021
+ True
1022
+ >>> distance_point_point((0.5, 0.0, 0.0), x) < 1e-6
1023
+ True
1024
+
1025
+ """
1026
+ for cd in pairwise(polyline):
1027
+ pt = intersection_segment_segment_xy(segment, cd, tol)
1028
+ if pt:
1029
+ return pt
1030
+
1031
+
1032
+ def intersection_ellipse_line_xy(ellipse, line):
1033
+ """Computes the intersection of an ellipse and a line in the XY plane.
1034
+
1035
+ Parameters
1036
+ ----------
1037
+ ellipse : tuple[float, float]
1038
+ The major and minor of the ellipse.
1039
+ line : [point, point] | :class:`compas.geometry.Line`
1040
+ A line defined by two points, with at least XY coordinates.
1041
+
1042
+ Returns
1043
+ -------
1044
+ tuple[[float, float, float], [float, float, float]] | [float, float, float] | None
1045
+ Two points, if the line goes through the ellipse.
1046
+ One point, if the line is tangent to the ellipse.
1047
+ None, otherwise.
1048
+
1049
+ References
1050
+ ----------
1051
+ Based on [1]_.
1052
+
1053
+ .. [1] C# Helper. *Calculate where a line segment and an ellipse intersect in C#*.
1054
+ Available at: http://csharphelper.com/blog/2017/08/calculate-where-a-line-segment-and-an-ellipse-intersect-in-c/
1055
+
1056
+ Examples
1057
+ --------
1058
+ >>> ellipse = 6.0, 2.5
1059
+ >>> p1 = (4.1, 2.8, 0.0)
1060
+ >>> p2 = (3.4, -3.1, 0.0)
1061
+ >>> i1, i2 = intersection_ellipse_line_xy(ellipse, [p1, p2])
1062
+
1063
+ """
1064
+ x1, y1 = line[0][0], line[0][1]
1065
+ x2, y2 = line[1][0], line[1][1]
1066
+
1067
+ a, b = ellipse
1068
+
1069
+ A = (x2 - x1) ** 2 / a**2 + (y2 - y1) ** 2 / b**2
1070
+ B = 2 * x1 * (x2 - x1) / a**2 + 2 * y1 * (y2 - y1) / b**2
1071
+ C = x1**2 / a**2 + y1**2 / b**2 - 1
1072
+
1073
+ discriminant = B**2 - 4 * A * C
1074
+ if discriminant == 0:
1075
+ t = -B / (2 * A)
1076
+ return (x1 + (x2 - x1) * t, y1 + (y2 - y1) * t, 0.0)
1077
+ elif discriminant > 0:
1078
+ t1 = (-B + sqrt(discriminant)) / (2 * A)
1079
+ t2 = (-B - sqrt(discriminant)) / (2 * A)
1080
+ p1 = (x1 + (x2 - x1) * t1, y1 + (y2 - y1) * t1, 0.0)
1081
+ p2 = (x1 + (x2 - x1) * t2, y1 + (y2 - y1) * t2, 0.0)
1082
+ return p1, p2
1083
+ else:
1084
+ return None
1085
+
1086
+
1087
+ # def intersection_line_circle_xy(line, circle):
1088
+ # """Compute the intersection of a line and a circle in the XY plane.
1089
+
1090
+ # Parameters
1091
+ # ----------
1092
+
1093
+ # """
1094
+ # x0, y0 = circle[0][:2]
1095
+ # r = circle[1]
1096
+ # x1, y1 = line[0][:2]
1097
+ # x2, y2 = line[1][:2]
1098
+ # a = y1 - y2
1099
+ # b = x2 - x1
1100
+ # c = x1 * y2 - x2 * y1
1101
+ # D = sqrt(r**2 - c**2 / (a**2 + b**2))
1102
+ # m = sqrt(D**2 / (a**2 + b**2))
1103
+ # p1 = [x0 + b * m, y0 - a * m, 0]
1104
+ # p2 = [x0 - b * m, y0 + a * m, 0]
1105
+ # return p1, p2