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.
- compas/__init__.py +274 -0
- compas/__main__.py +31 -0
- compas/_iotools.py +80 -0
- compas/_os.py +746 -0
- compas/colors/__init__.py +14 -0
- compas/colors/cmcrameri/acton.txt +256 -0
- compas/colors/cmcrameri/actonS.txt +100 -0
- compas/colors/cmcrameri/bam.txt +256 -0
- compas/colors/cmcrameri/bamO.txt +256 -0
- compas/colors/cmcrameri/bamako.txt +256 -0
- compas/colors/cmcrameri/bamakoS.txt +100 -0
- compas/colors/cmcrameri/batlow.txt +256 -0
- compas/colors/cmcrameri/batlowK.txt +256 -0
- compas/colors/cmcrameri/batlowS.txt +100 -0
- compas/colors/cmcrameri/batlowW.txt +256 -0
- compas/colors/cmcrameri/berlin.txt +256 -0
- compas/colors/cmcrameri/bilbao.txt +256 -0
- compas/colors/cmcrameri/bilbaoS.txt +100 -0
- compas/colors/cmcrameri/broc.txt +256 -0
- compas/colors/cmcrameri/brocO.txt +256 -0
- compas/colors/cmcrameri/buda.txt +256 -0
- compas/colors/cmcrameri/budaS.txt +100 -0
- compas/colors/cmcrameri/bukavu.txt +256 -0
- compas/colors/cmcrameri/cork.txt +256 -0
- compas/colors/cmcrameri/corkO.txt +256 -0
- compas/colors/cmcrameri/davos.txt +256 -0
- compas/colors/cmcrameri/davosS.txt +100 -0
- compas/colors/cmcrameri/devon.txt +256 -0
- compas/colors/cmcrameri/devonS.txt +100 -0
- compas/colors/cmcrameri/fes.txt +256 -0
- compas/colors/cmcrameri/grayC.txt +256 -0
- compas/colors/cmcrameri/grayCS.txt +100 -0
- compas/colors/cmcrameri/hawaii.txt +256 -0
- compas/colors/cmcrameri/hawaiiS.txt +100 -0
- compas/colors/cmcrameri/imola.txt +256 -0
- compas/colors/cmcrameri/imolaS.txt +100 -0
- compas/colors/cmcrameri/lajolla.txt +256 -0
- compas/colors/cmcrameri/lajollaS.txt +100 -0
- compas/colors/cmcrameri/lapaz.txt +256 -0
- compas/colors/cmcrameri/lapazS.txt +100 -0
- compas/colors/cmcrameri/lisbon.txt +256 -0
- compas/colors/cmcrameri/nuuk.txt +256 -0
- compas/colors/cmcrameri/nuukS.txt +100 -0
- compas/colors/cmcrameri/oleron.txt +256 -0
- compas/colors/cmcrameri/oslo.txt +256 -0
- compas/colors/cmcrameri/osloS.txt +100 -0
- compas/colors/cmcrameri/roma.txt +256 -0
- compas/colors/cmcrameri/romaO.txt +256 -0
- compas/colors/cmcrameri/tofino.txt +256 -0
- compas/colors/cmcrameri/tokyo.txt +256 -0
- compas/colors/cmcrameri/tokyoS.txt +100 -0
- compas/colors/cmcrameri/turku.txt +256 -0
- compas/colors/cmcrameri/turkuS.txt +100 -0
- compas/colors/cmcrameri/vanimo.txt +256 -0
- compas/colors/cmcrameri/vik.txt +256 -0
- compas/colors/cmcrameri/vikO.txt +256 -0
- compas/colors/color.py +1118 -0
- compas/colors/colordict.py +103 -0
- compas/colors/colormap.py +306 -0
- compas/colors/html_colors.py +149 -0
- compas/colors/mpl_colormap.py +1064 -0
- compas/data/__init__.py +31 -0
- compas/data/coercion.py +71 -0
- compas/data/conftest.py +10 -0
- compas/data/data.py +342 -0
- compas/data/encoders.py +240 -0
- compas/data/exceptions.py +2 -0
- compas/data/json.py +240 -0
- compas/data/samples/boxes.obj +250 -0
- compas/data/samples/butt_model.obj +2829 -0
- compas/data/samples/cone.stl +0 -0
- compas/data/samples/cube.off +16 -0
- compas/data/samples/cube_ascii.stl +56114 -0
- compas/data/samples/cube_binary.stl +0 -0
- compas/data/samples/cube_binary_2.stl +0 -0
- compas/data/samples/doosabin.json +1 -0
- compas/data/samples/faces.obj +63 -0
- compas/data/samples/faces_big.obj +9663 -0
- compas/data/samples/faces_reversed.obj +63 -0
- compas/data/samples/fink.obj +135 -0
- compas/data/samples/grid_irregular.obj +303 -0
- compas/data/samples/hypar.obj +148 -0
- compas/data/samples/lines.json +1 -0
- compas/data/samples/lines.obj +282 -0
- compas/data/samples/lines_big.obj +40322 -0
- compas/data/samples/lines_bigger.obj +161282 -0
- compas/data/samples/lines_noleaves.obj +422 -0
- compas/data/samples/mesh.obj +874 -0
- compas/data/samples/mesh_100_faces.json +1893 -0
- compas/data/samples/mesh_110_faces.json +2081 -0
- compas/data/samples/open_edges.obj +424 -0
- compas/data/samples/point.json +1 -0
- compas/data/samples/quadmesh.obj +183 -0
- compas/data/samples/quadmesh_planar.obj +181 -0
- compas/data/samples/saddle.obj +314 -0
- compas/data/samples/spline.obj +72 -0
- compas/data/samples/tubemesh.json +1 -0
- compas/data/samples/tubemesh.obj +378 -0
- compas/data/samples/tubemesh.off +374 -0
- compas/data/samples/tubemesh.ply +551 -0
- compas/data/schema.py +137 -0
- compas/data/validators.py +243 -0
- compas/datastructures/__init__.py +75 -0
- compas/datastructures/_mutablemapping.py +148 -0
- compas/datastructures/assembly/__init__.py +0 -0
- compas/datastructures/assembly/assembly.py +234 -0
- compas/datastructures/assembly/exceptions.py +6 -0
- compas/datastructures/assembly/part.py +228 -0
- compas/datastructures/attributes.py +85 -0
- compas/datastructures/cell_network/__init__.py +0 -0
- compas/datastructures/cell_network/cell_network.py +4190 -0
- compas/datastructures/datastructure.py +309 -0
- compas/datastructures/graph/__init__.py +0 -0
- compas/datastructures/graph/duality.py +197 -0
- compas/datastructures/graph/graph.py +2478 -0
- compas/datastructures/graph/operations/__init__.py +0 -0
- compas/datastructures/graph/operations/join.py +124 -0
- compas/datastructures/graph/operations/split.py +63 -0
- compas/datastructures/graph/planarity.py +292 -0
- compas/datastructures/graph/smoothing.py +59 -0
- compas/datastructures/mesh/__init__.py +0 -0
- compas/datastructures/mesh/conway.py +553 -0
- compas/datastructures/mesh/duality.py +104 -0
- compas/datastructures/mesh/mesh.py +5103 -0
- compas/datastructures/mesh/operations/__init__.py +0 -0
- compas/datastructures/mesh/operations/collapse.py +350 -0
- compas/datastructures/mesh/operations/extrude.py +0 -0
- compas/datastructures/mesh/operations/insert.py +120 -0
- compas/datastructures/mesh/operations/merge.py +83 -0
- compas/datastructures/mesh/operations/split.py +263 -0
- compas/datastructures/mesh/operations/substitute.py +37 -0
- compas/datastructures/mesh/operations/swap.py +62 -0
- compas/datastructures/mesh/operations/weld.py +107 -0
- compas/datastructures/mesh/remesh.py +234 -0
- compas/datastructures/mesh/slice.py +170 -0
- compas/datastructures/mesh/smoothing.py +187 -0
- compas/datastructures/mesh/subdivision.py +754 -0
- compas/datastructures/tree/__init__.py +0 -0
- compas/datastructures/tree/tree.py +504 -0
- compas/datastructures/volmesh/__init__.py +0 -0
- compas/datastructures/volmesh/volmesh.py +4203 -0
- compas/files/__init__.py +27 -0
- compas/files/_xml/__init__.py +0 -0
- compas/files/_xml/xml_cli.py +213 -0
- compas/files/_xml/xml_cpython.py +32 -0
- compas/files/_xml/xml_pre_38.py +58 -0
- compas/files/_xml/xml_shared.py +40 -0
- compas/files/gltf/__init__.py +0 -0
- compas/files/gltf/constants.py +59 -0
- compas/files/gltf/data_classes.py +657 -0
- compas/files/gltf/extensions.py +317 -0
- compas/files/gltf/gltf.py +92 -0
- compas/files/gltf/gltf_children.py +64 -0
- compas/files/gltf/gltf_content.py +615 -0
- compas/files/gltf/gltf_exporter.py +465 -0
- compas/files/gltf/gltf_mesh.py +273 -0
- compas/files/gltf/gltf_node.py +348 -0
- compas/files/gltf/gltf_parser.py +115 -0
- compas/files/gltf/gltf_reader.py +310 -0
- compas/files/gltf/gltf_scene.py +125 -0
- compas/files/gltf/helpers.py +59 -0
- compas/files/obj.py +680 -0
- compas/files/off.py +296 -0
- compas/files/ply.py +697 -0
- compas/files/stl.py +436 -0
- compas/files/xml.py +328 -0
- compas/geometry/__init__.py +772 -0
- compas/geometry/_core/__init__.py +0 -0
- compas/geometry/_core/_algebra.py +2826 -0
- compas/geometry/_core/angles.py +408 -0
- compas/geometry/_core/centroids.py +573 -0
- compas/geometry/_core/distance.py +895 -0
- compas/geometry/_core/normals.py +149 -0
- compas/geometry/_core/nurbs.py +367 -0
- compas/geometry/_core/predicates_2.py +582 -0
- compas/geometry/_core/predicates_3.py +1111 -0
- compas/geometry/_core/quaternions.py +196 -0
- compas/geometry/_core/size.py +204 -0
- compas/geometry/_core/tangent.py +56 -0
- compas/geometry/_core/transformations.py +1121 -0
- compas/geometry/_core/transformations_numpy.py +279 -0
- compas/geometry/bbox.py +145 -0
- compas/geometry/bbox_numpy.py +306 -0
- compas/geometry/bestfit.py +77 -0
- compas/geometry/bestfit_numpy.py +259 -0
- compas/geometry/booleans.py +297 -0
- compas/geometry/booleans_shapely.py +147 -0
- compas/geometry/brep/__init__.py +112 -0
- compas/geometry/brep/brep.py +1131 -0
- compas/geometry/brep/edge.py +302 -0
- compas/geometry/brep/errors.py +22 -0
- compas/geometry/brep/face.py +329 -0
- compas/geometry/brep/loop.py +87 -0
- compas/geometry/brep/trim.py +46 -0
- compas/geometry/brep/vertex.py +46 -0
- compas/geometry/contours.py +32 -0
- compas/geometry/curves/__init__.py +0 -0
- compas/geometry/curves/arc.py +429 -0
- compas/geometry/curves/bezier.py +345 -0
- compas/geometry/curves/circle.py +500 -0
- compas/geometry/curves/conic.py +16 -0
- compas/geometry/curves/curve.py +614 -0
- compas/geometry/curves/ellipse.py +408 -0
- compas/geometry/curves/hyperbola.py +336 -0
- compas/geometry/curves/line.py +431 -0
- compas/geometry/curves/nurbs.py +412 -0
- compas/geometry/curves/parabola.py +256 -0
- compas/geometry/curves/polyline.py +724 -0
- compas/geometry/frame.py +769 -0
- compas/geometry/geometry.py +296 -0
- compas/geometry/hull.py +146 -0
- compas/geometry/hull_numpy.py +82 -0
- compas/geometry/icp_numpy.py +104 -0
- compas/geometry/interpolation_barycentric.py +38 -0
- compas/geometry/interpolation_coons.py +102 -0
- compas/geometry/interpolation_tweening.py +87 -0
- compas/geometry/intersection.py +121 -0
- compas/geometry/intersections.py +1105 -0
- compas/geometry/kdtree.py +153 -0
- compas/geometry/offset.py +208 -0
- compas/geometry/pca_numpy.py +87 -0
- compas/geometry/plane.py +657 -0
- compas/geometry/point.py +664 -0
- compas/geometry/pointcloud.py +409 -0
- compas/geometry/polygon.py +473 -0
- compas/geometry/polyhedron.py +650 -0
- compas/geometry/projection.py +155 -0
- compas/geometry/quadmesh_planarize.py +30 -0
- compas/geometry/quadmesh_planarize_none.py +114 -0
- compas/geometry/quaternion.py +544 -0
- compas/geometry/reflection.py +102 -0
- compas/geometry/rotation.py +354 -0
- compas/geometry/scale.py +100 -0
- compas/geometry/shapes/__init__.py +0 -0
- compas/geometry/shapes/box.py +747 -0
- compas/geometry/shapes/capsule.py +472 -0
- compas/geometry/shapes/cone.py +309 -0
- compas/geometry/shapes/cylinder.py +355 -0
- compas/geometry/shapes/shape.py +300 -0
- compas/geometry/shapes/sphere.py +362 -0
- compas/geometry/shapes/torus.py +294 -0
- compas/geometry/shear.py +115 -0
- compas/geometry/surfaces/__init__.py +0 -0
- compas/geometry/surfaces/conical.py +166 -0
- compas/geometry/surfaces/cylindrical.py +251 -0
- compas/geometry/surfaces/extrusion.py +0 -0
- compas/geometry/surfaces/nurbs.py +380 -0
- compas/geometry/surfaces/planar.py +223 -0
- compas/geometry/surfaces/revolution.py +0 -0
- compas/geometry/surfaces/spherical.py +259 -0
- compas/geometry/surfaces/surface.py +689 -0
- compas/geometry/surfaces/toroidal.py +198 -0
- compas/geometry/transformation.py +554 -0
- compas/geometry/translation.py +104 -0
- compas/geometry/triangulation_delaunay.py +102 -0
- compas/geometry/triangulation_earclip.py +300 -0
- compas/geometry/trimesh_curvature.py +113 -0
- compas/geometry/trimesh_descent_numpy.py +26 -0
- compas/geometry/trimesh_geodistance.py +35 -0
- compas/geometry/trimesh_gradient_numpy.py +74 -0
- compas/geometry/trimesh_isolines.py +41 -0
- compas/geometry/trimesh_matrices.py +31 -0
- compas/geometry/trimesh_matrices_numpy.py +191 -0
- compas/geometry/trimesh_parametrisation.py +55 -0
- compas/geometry/trimesh_pull_points_numpy.py +216 -0
- compas/geometry/trimesh_remeshing.py +97 -0
- compas/geometry/trimesh_samplepoints_numpy.py +108 -0
- compas/geometry/trimesh_slicing.py +28 -0
- compas/geometry/trimesh_smoothing_numpy.py +34 -0
- compas/geometry/vector.py +889 -0
- compas/itertools.py +441 -0
- compas/linalg.py +634 -0
- compas/matrices.py +314 -0
- compas/plugins.py +488 -0
- compas/rpc/__init__.py +20 -0
- compas/rpc/__main__.py +77 -0
- compas/rpc/dispatcher.py +181 -0
- compas/rpc/errors.py +11 -0
- compas/rpc/proxy.py +437 -0
- compas/rpc/server.py +79 -0
- compas/rpc/services/__init__.py +0 -0
- compas/rpc/services/default.py +87 -0
- compas/rpc/services/watcher.py +43 -0
- compas/scene/__init__.py +56 -0
- compas/scene/assemblyobject.py +3 -0
- compas/scene/context.py +154 -0
- compas/scene/descriptors/__init__.py +0 -0
- compas/scene/descriptors/attribute.py +30 -0
- compas/scene/descriptors/color.py +91 -0
- compas/scene/descriptors/colordict.py +101 -0
- compas/scene/descriptors/protocol.py +12 -0
- compas/scene/exceptions.py +7 -0
- compas/scene/geometryobject.py +58 -0
- compas/scene/graphobject.py +173 -0
- compas/scene/meshobject.py +238 -0
- compas/scene/scene.py +144 -0
- compas/scene/sceneobject.py +253 -0
- compas/scene/volmeshobject.py +252 -0
- compas/tolerance.py +879 -0
- compas/topology/__init__.py +45 -0
- compas/topology/combinatorics.py +108 -0
- compas/topology/connectivity.py +129 -0
- compas/topology/orientation.py +204 -0
- compas/topology/traversal.py +567 -0
- compas/utilities/__init__.py +25 -0
- compas/utilities/azync.py +155 -0
- compas/utilities/datetime.py +40 -0
- compas/utilities/decorators.py +136 -0
- compas/utilities/remote.py +54 -0
- compas/utilities/ssh.py +169 -0
- compas-2.1.1.dist-info/AUTHORS.md +42 -0
- compas-2.1.1.dist-info/LICENSE +21 -0
- compas-2.1.1.dist-info/METADATA +132 -0
- compas-2.1.1.dist-info/RECORD +468 -0
- compas-2.1.1.dist-info/WHEEL +5 -0
- compas-2.1.1.dist-info/entry_points.txt +2 -0
- compas-2.1.1.dist-info/top_level.txt +4 -0
- compas_blender/__init__.py +250 -0
- compas_blender/collections.py +130 -0
- compas_blender/conversions/__init__.py +48 -0
- compas_blender/conversions/breps.py +0 -0
- compas_blender/conversions/colors.py +23 -0
- compas_blender/conversions/curves.py +125 -0
- compas_blender/conversions/geometry.py +161 -0
- compas_blender/conversions/meshes.py +148 -0
- compas_blender/conversions/surfaces.py +48 -0
- compas_blender/conversions/transformations.py +46 -0
- compas_blender/data.py +30 -0
- compas_blender/geometry/__init__.py +14 -0
- compas_blender/geometry/booleans.py +100 -0
- compas_blender/install.py +338 -0
- compas_blender/objects.py +326 -0
- compas_blender/print_python_path.py +18 -0
- compas_blender/scene/__init__.py +116 -0
- compas_blender/scene/boxobject.py +64 -0
- compas_blender/scene/capsuleobject.py +73 -0
- compas_blender/scene/circleobject.py +53 -0
- compas_blender/scene/coneobject.py +70 -0
- compas_blender/scene/curveobject.py +58 -0
- compas_blender/scene/cylinderobject.py +70 -0
- compas_blender/scene/frameobject.py +105 -0
- compas_blender/scene/graphobject.py +257 -0
- compas_blender/scene/lineobject.py +60 -0
- compas_blender/scene/meshobject.py +508 -0
- compas_blender/scene/planeobject.py +81 -0
- compas_blender/scene/pointcloudobject.py +67 -0
- compas_blender/scene/pointobject.py +71 -0
- compas_blender/scene/polygonobject.py +57 -0
- compas_blender/scene/polyhedronobject.py +57 -0
- compas_blender/scene/polylineobject.py +54 -0
- compas_blender/scene/sceneobject.py +249 -0
- compas_blender/scene/sphereobject.py +72 -0
- compas_blender/scene/surfaceobject.py +54 -0
- compas_blender/scene/torusobject.py +73 -0
- compas_blender/scene/vectorobject.py +69 -0
- compas_blender/scene/volmeshobject.py +475 -0
- compas_blender/utilities/__init__.py +38 -0
- compas_blender/utilities/drawing.py +768 -0
- compas_ghpython/__init__.py +124 -0
- compas_ghpython/components/Compas_FromJson/code.py +18 -0
- compas_ghpython/components/Compas_Info/code.py +15 -0
- compas_ghpython/components/Compas_RpcCall/code.py +31 -0
- compas_ghpython/components/Compas_ToJson/code.py +19 -0
- compas_ghpython/components/Compas_ToRhinoGeometry/code.py +15 -0
- compas_ghpython/components/__init__.py +99 -0
- compas_ghpython/install.py +29 -0
- compas_ghpython/scene/__init__.py +115 -0
- compas_ghpython/scene/boxobject.py +40 -0
- compas_ghpython/scene/brepobject.py +40 -0
- compas_ghpython/scene/capsuleobject.py +41 -0
- compas_ghpython/scene/circleobject.py +40 -0
- compas_ghpython/scene/coneobject.py +40 -0
- compas_ghpython/scene/curveobject.py +42 -0
- compas_ghpython/scene/cylinderobject.py +38 -0
- compas_ghpython/scene/ellipseobject.py +40 -0
- compas_ghpython/scene/frameobject.py +67 -0
- compas_ghpython/scene/graphobject.py +77 -0
- compas_ghpython/scene/lineobject.py +39 -0
- compas_ghpython/scene/meshobject.py +137 -0
- compas_ghpython/scene/planeobject.py +61 -0
- compas_ghpython/scene/pointobject.py +38 -0
- compas_ghpython/scene/polygonobject.py +48 -0
- compas_ghpython/scene/polyhedronobject.py +48 -0
- compas_ghpython/scene/polylineobject.py +39 -0
- compas_ghpython/scene/sceneobject.py +12 -0
- compas_ghpython/scene/sphereobject.py +39 -0
- compas_ghpython/scene/surfaceobject.py +42 -0
- compas_ghpython/scene/torusobject.py +39 -0
- compas_ghpython/scene/vectorobject.py +51 -0
- compas_ghpython/scene/volmeshobject.py +154 -0
- compas_ghpython/sets.py +83 -0
- compas_ghpython/timer.py +36 -0
- compas_ghpython/uninstall.py +31 -0
- compas_ghpython/utilities/__init__.py +33 -0
- compas_ghpython/utilities/drawing.py +457 -0
- compas_rhino/__init__.py +607 -0
- compas_rhino/conduits/__init__.py +16 -0
- compas_rhino/conduits/base.py +121 -0
- compas_rhino/conduits/faces.py +91 -0
- compas_rhino/conduits/labels.py +102 -0
- compas_rhino/conduits/lines.py +109 -0
- compas_rhino/conduits/points.py +111 -0
- compas_rhino/conversions/__init__.py +168 -0
- compas_rhino/conversions/breps.py +122 -0
- compas_rhino/conversions/curves.py +453 -0
- compas_rhino/conversions/docobjects.py +0 -0
- compas_rhino/conversions/exceptions.py +7 -0
- compas_rhino/conversions/extrusions.py +80 -0
- compas_rhino/conversions/geometry.py +187 -0
- compas_rhino/conversions/meshes.py +281 -0
- compas_rhino/conversions/shapes.py +291 -0
- compas_rhino/conversions/surfaces.py +355 -0
- compas_rhino/conversions/transformations.py +45 -0
- compas_rhino/geometry/__init__.py +44 -0
- compas_rhino/geometry/booleans.py +118 -0
- compas_rhino/geometry/brep/__init__.py +40 -0
- compas_rhino/geometry/brep/brep.py +554 -0
- compas_rhino/geometry/brep/builder.py +184 -0
- compas_rhino/geometry/brep/edge.py +202 -0
- compas_rhino/geometry/brep/face.py +285 -0
- compas_rhino/geometry/brep/loop.py +129 -0
- compas_rhino/geometry/brep/trim.py +99 -0
- compas_rhino/geometry/brep/vertex.py +76 -0
- compas_rhino/geometry/curves/__init__.py +43 -0
- compas_rhino/geometry/curves/curve.py +382 -0
- compas_rhino/geometry/curves/nurbs.py +298 -0
- compas_rhino/geometry/surfaces/__init__.py +50 -0
- compas_rhino/geometry/surfaces/nurbs.py +370 -0
- compas_rhino/geometry/surfaces/surface.py +407 -0
- compas_rhino/geometry/trimesh_curvature.py +344 -0
- compas_rhino/geometry/trimesh_slicing.py +65 -0
- compas_rhino/install.py +382 -0
- compas_rhino/install_plugin.py +169 -0
- compas_rhino/install_with_pip.py +20 -0
- compas_rhino/layers.py +347 -0
- compas_rhino/objects.py +1141 -0
- compas_rhino/print_python_path.py +18 -0
- compas_rhino/scene/__init__.py +123 -0
- compas_rhino/scene/boxobject.py +44 -0
- compas_rhino/scene/brepobject.py +41 -0
- compas_rhino/scene/capsuleobject.py +45 -0
- compas_rhino/scene/circleobject.py +43 -0
- compas_rhino/scene/coneobject.py +43 -0
- compas_rhino/scene/curveobject.py +43 -0
- compas_rhino/scene/cylinderobject.py +43 -0
- compas_rhino/scene/ellipseobject.py +44 -0
- compas_rhino/scene/frameobject.py +99 -0
- compas_rhino/scene/graphobject.py +364 -0
- compas_rhino/scene/helpers.py +33 -0
- compas_rhino/scene/lineobject.py +43 -0
- compas_rhino/scene/meshobject.py +673 -0
- compas_rhino/scene/planeobject.py +71 -0
- compas_rhino/scene/pointobject.py +43 -0
- compas_rhino/scene/polygonobject.py +45 -0
- compas_rhino/scene/polyhedronobject.py +45 -0
- compas_rhino/scene/polylineobject.py +43 -0
- compas_rhino/scene/sceneobject.py +123 -0
- compas_rhino/scene/sphereobject.py +43 -0
- compas_rhino/scene/surfaceobject.py +42 -0
- compas_rhino/scene/torusobject.py +43 -0
- compas_rhino/scene/vectorobject.py +49 -0
- compas_rhino/scene/volmeshobject.py +518 -0
- compas_rhino/ui.py +114 -0
- compas_rhino/uninstall.py +243 -0
- compas_rhino/uninstall_plugin.py +91 -0
- compas_rhino/utilities/__init__.py +37 -0
- compas_rhino/utilities/constructors.py +71 -0
- compas_rhino/utilities/drawing.py +1081 -0
|
@@ -0,0 +1,1121 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
from ._algebra import add_vectors
|
|
8
|
+
from ._algebra import add_vectors_xy
|
|
9
|
+
from ._algebra import cross_vectors
|
|
10
|
+
from ._algebra import dot_vectors
|
|
11
|
+
from ._algebra import matrix_from_axis_and_angle
|
|
12
|
+
from ._algebra import matrix_from_change_of_basis
|
|
13
|
+
from ._algebra import matrix_from_scale_factors
|
|
14
|
+
from ._algebra import multiply_matrices
|
|
15
|
+
from ._algebra import multiply_matrix_vector
|
|
16
|
+
from ._algebra import norm_vector
|
|
17
|
+
from ._algebra import normalize_vector
|
|
18
|
+
from ._algebra import scale_vector
|
|
19
|
+
from ._algebra import scale_vector_xy
|
|
20
|
+
from ._algebra import subtract_vectors
|
|
21
|
+
from ._algebra import subtract_vectors_xy
|
|
22
|
+
from ._algebra import transpose_matrix
|
|
23
|
+
from ._algebra import vector_component
|
|
24
|
+
from ._algebra import vector_component_xy
|
|
25
|
+
from .angles import angle_vectors
|
|
26
|
+
from .distance import closest_point_on_line
|
|
27
|
+
from .distance import closest_point_on_line_xy
|
|
28
|
+
from .distance import closest_point_on_plane
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# this function will not always work
|
|
32
|
+
# it is also a duplicate of stuff found in matrices and frame
|
|
33
|
+
def local_axes(a, b, c):
|
|
34
|
+
u = b - a
|
|
35
|
+
v = c - a
|
|
36
|
+
w = cross_vectors(u, v)
|
|
37
|
+
v = cross_vectors(w, u)
|
|
38
|
+
return normalize_vector(u), normalize_vector(v), normalize_vector(w)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def orthonormalize_axes(xaxis, yaxis):
|
|
42
|
+
"""Corrects xaxis and yaxis to be unit vectors and orthonormal.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
xaxis: [float, float, float] | :class:`compas.geometry.Vector`
|
|
47
|
+
The first axis.
|
|
48
|
+
yaxis: [float, float, float] | :class:`compas.geometry.Vector`
|
|
49
|
+
The second axis.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
[float, float, float]
|
|
54
|
+
The corrected x axis.
|
|
55
|
+
[float, float, float]
|
|
56
|
+
The corrected y axis.
|
|
57
|
+
|
|
58
|
+
Raises
|
|
59
|
+
------
|
|
60
|
+
ValueError
|
|
61
|
+
If xaxis and yaxis cannot span a plane.
|
|
62
|
+
|
|
63
|
+
Examples
|
|
64
|
+
--------
|
|
65
|
+
>>> from compas.tolerance import TOL
|
|
66
|
+
>>> xaxis = [1, 4, 5]
|
|
67
|
+
>>> yaxis = [1, 0, -2]
|
|
68
|
+
>>> xaxis, yaxis = orthonormalize_axes(xaxis, yaxis)
|
|
69
|
+
>>> TOL.is_allclose(xaxis, [0.1543, 0.6172, 0.7715], atol=0.001)
|
|
70
|
+
True
|
|
71
|
+
>>> TOL.is_allclose(yaxis, [0.6929, 0.4891, -0.5298], atol=0.001)
|
|
72
|
+
True
|
|
73
|
+
|
|
74
|
+
"""
|
|
75
|
+
xaxis = normalize_vector(xaxis)
|
|
76
|
+
yaxis = normalize_vector(yaxis)
|
|
77
|
+
zaxis = cross_vectors(xaxis, yaxis)
|
|
78
|
+
if not norm_vector(zaxis):
|
|
79
|
+
raise ValueError("Xaxis and yaxis cannot span a plane.")
|
|
80
|
+
yaxis = cross_vectors(normalize_vector(zaxis), xaxis)
|
|
81
|
+
return xaxis, yaxis
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def homogenize(xyz, w=1.0):
|
|
85
|
+
"""Homogenise a list of vectors.
|
|
86
|
+
|
|
87
|
+
Parameters
|
|
88
|
+
----------
|
|
89
|
+
xyz : sequence[[float, float, float] | :class:`compas.geometry.Point`] | sequence[[float, float, float] | :class:`compas.geometry.Vector`]
|
|
90
|
+
A list of points or vectors.
|
|
91
|
+
w : float, optional
|
|
92
|
+
Homogenisation parameter.
|
|
93
|
+
Use ``1.0`` for points, and ``0.0`` for vectors.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
list[[float, float, float, `w`]]
|
|
98
|
+
Homogenised data.
|
|
99
|
+
|
|
100
|
+
Notes
|
|
101
|
+
-----
|
|
102
|
+
Vectors described by XYZ components are homogenised by appending a homogenisation
|
|
103
|
+
parameter to the components, and by dividing each component by that parameter.
|
|
104
|
+
Homogenisatioon of vectors is often used in relation to transformations.
|
|
105
|
+
|
|
106
|
+
Examples
|
|
107
|
+
--------
|
|
108
|
+
>>> vectors = [[1.0, 0.0, 0.0]]
|
|
109
|
+
>>> homogenize(vectors)
|
|
110
|
+
[[1.0, 0.0, 0.0, 1.0]]
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
return [[x * w, y * w, z * w, w] if w else [x, y, z, 0.0] for x, y, z in xyz]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def dehomogenize(xyzw):
|
|
117
|
+
"""Dehomogenise a list of vectors.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
xyzw : sequence[[float, float, float, `w`]]
|
|
122
|
+
A list of vectors.
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
-------
|
|
126
|
+
list[[float, float, float]]
|
|
127
|
+
Dehomogenised vectors.
|
|
128
|
+
|
|
129
|
+
Examples
|
|
130
|
+
--------
|
|
131
|
+
>>>
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
return [[x / w, y / w, z / w] if w else [x, y, z] for x, y, z, w in xyzw]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def homogenize_and_flatten_frames(frames):
|
|
138
|
+
"""Homogenize a list of frames and flatten the 3D list into a 2D list.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
frames : sequence[[point, vector, vector]]
|
|
143
|
+
|
|
144
|
+
Returns
|
|
145
|
+
-------
|
|
146
|
+
list[[float, float, float, `w`]]
|
|
147
|
+
A list with 3 entries per frame: a homogenized point, and two homogenized vectors.
|
|
148
|
+
|
|
149
|
+
Examples
|
|
150
|
+
--------
|
|
151
|
+
>>> from compas.geometry import Frame
|
|
152
|
+
>>> frames = [Frame((1, 1, 1), (0, 1, 0), (1, 0, 0))]
|
|
153
|
+
>>> homogenize_and_flatten_frames(frames)
|
|
154
|
+
[[1.0, 1.0, 1.0, 1.0], [0.0, 1.0, 0.0, 0.0], [1.0, -0.0, 0.0, 0.0]]
|
|
155
|
+
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
def homogenize_frame(frame):
|
|
159
|
+
return homogenize([frame[0]], w=1.0) + homogenize([frame[1], frame[2]], w=0.0)
|
|
160
|
+
|
|
161
|
+
return [v for frame in frames for v in homogenize_frame(frame)]
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def dehomogenize_and_unflatten_frames(points_and_vectors):
|
|
165
|
+
"""Dehomogenize a list of vectors and unflatten the 2D list into a 3D list.
|
|
166
|
+
|
|
167
|
+
Parameters
|
|
168
|
+
----------
|
|
169
|
+
points_and_vectors : sequence[[float, float, float, `w`]]
|
|
170
|
+
List of homogenized frames with 3 entries per frame: a homogenized point, and two homogenized vectors.
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
list[[point, vector, vector]]
|
|
175
|
+
The dehmogenized frame data.
|
|
176
|
+
|
|
177
|
+
Examples
|
|
178
|
+
--------
|
|
179
|
+
>>> points_and_vectors = [(1.0, 1.0, 1.0, 1.0), (0.0, 1.0, 0.0, 0.0), (1.0, 0.0, 0.0, 0.0)]
|
|
180
|
+
>>> dehomogenize_and_unflatten_frames(points_and_vectors)
|
|
181
|
+
[[[1.0, 1.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]]]
|
|
182
|
+
|
|
183
|
+
"""
|
|
184
|
+
frames = dehomogenize(points_and_vectors)
|
|
185
|
+
return [frames[i : i + 3] for i in range(0, len(frames), 3)]
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ==============================================================================
|
|
189
|
+
# transform
|
|
190
|
+
# ==============================================================================
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def transform_points(points, T):
|
|
194
|
+
"""Transform multiple points with one transformation matrix.
|
|
195
|
+
|
|
196
|
+
Parameters
|
|
197
|
+
----------
|
|
198
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
199
|
+
A list of points to be transformed.
|
|
200
|
+
T : list[list[float]] | :class:`compas.geometry.Transformation`
|
|
201
|
+
The transformation to apply.
|
|
202
|
+
|
|
203
|
+
Returns
|
|
204
|
+
-------
|
|
205
|
+
list[[float, float, float]]
|
|
206
|
+
Transformed points.
|
|
207
|
+
|
|
208
|
+
Examples
|
|
209
|
+
--------
|
|
210
|
+
>>> points = [[1, 0, 0], [1, 2, 4], [4, 7, 1]]
|
|
211
|
+
>>> T = matrix_from_axis_and_angle([0, 2, 0], math.radians(45), point=[4, 5, 6])
|
|
212
|
+
>>> points_transformed = transform_points(points, T)
|
|
213
|
+
|
|
214
|
+
"""
|
|
215
|
+
return dehomogenize(multiply_matrices(homogenize(points, w=1.0), transpose_matrix(T)))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def transform_vectors(vectors, T):
|
|
219
|
+
"""Transform multiple vectors with one transformation matrix.
|
|
220
|
+
|
|
221
|
+
Parameters
|
|
222
|
+
----------
|
|
223
|
+
vectors : sequence[[float, float, float] | :class:`compas.geometry.Vector`]
|
|
224
|
+
A list of vectors to be transformed.
|
|
225
|
+
T : list[list[float]] | :class:`compas.geometry.Transformation`
|
|
226
|
+
The transformation to apply.
|
|
227
|
+
|
|
228
|
+
Returns
|
|
229
|
+
-------
|
|
230
|
+
list[[float, float, float]]
|
|
231
|
+
Transformed vectors.
|
|
232
|
+
|
|
233
|
+
Examples
|
|
234
|
+
--------
|
|
235
|
+
>>> vectors = [[1, 0, 0], [1, 2, 4], [4, 7, 1]]
|
|
236
|
+
>>> T = matrix_from_axis_and_angle([0, 2, 0], math.radians(45), point=[4, 5, 6])
|
|
237
|
+
>>> vectors_transformed = transform_vectors(vectors, T)
|
|
238
|
+
|
|
239
|
+
"""
|
|
240
|
+
return dehomogenize(multiply_matrices(homogenize(vectors, w=0.0), transpose_matrix(T)))
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def transform_frames(frames, T):
|
|
244
|
+
"""Transform multiple frames with one transformation matrix.
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
frames : sequence[[point, vector, vector]]
|
|
249
|
+
A list of frames to be transformed.
|
|
250
|
+
T : list[list[float]] | :class:`compas.geometry.Transformation`
|
|
251
|
+
The transformation to apply on the frames.
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
list[[point, vector, vector]]
|
|
256
|
+
Transformed frames.
|
|
257
|
+
|
|
258
|
+
Examples
|
|
259
|
+
--------
|
|
260
|
+
>>> from compas.geometry import Frame, matrix_from_axis_and_angle
|
|
261
|
+
>>> frames = [Frame([1, 0, 0], [1, 2, 4], [4, 7, 1]), Frame([0, 2, 0], [5, 2, 1], [0, 2, 1])]
|
|
262
|
+
>>> T = matrix_from_axis_and_angle([0, 2, 0], math.radians(45), point=[4, 5, 6])
|
|
263
|
+
>>> transformed_frames = transform_frames(frames, T)
|
|
264
|
+
|
|
265
|
+
"""
|
|
266
|
+
points_and_vectors = homogenize_and_flatten_frames(frames)
|
|
267
|
+
return dehomogenize_and_unflatten_frames(multiply_matrices(points_and_vectors, transpose_matrix(T)))
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def world_to_local_coordinates(frame, xyz):
|
|
271
|
+
"""Convert global coordinates to local coordinates.
|
|
272
|
+
|
|
273
|
+
Parameters
|
|
274
|
+
----------
|
|
275
|
+
frame : [point, vector, vector]
|
|
276
|
+
The local coordinate system.
|
|
277
|
+
xyz : array-like[[float, float, float] | :class:`compas.geometry.Point`]
|
|
278
|
+
The global coordinates of the points to convert.
|
|
279
|
+
|
|
280
|
+
Returns
|
|
281
|
+
-------
|
|
282
|
+
list[[float, float, float]]
|
|
283
|
+
The coordinates of the given points in the local coordinate system.
|
|
284
|
+
|
|
285
|
+
Examples
|
|
286
|
+
--------
|
|
287
|
+
>>> from compas.geometry import Point, Frame
|
|
288
|
+
>>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9])
|
|
289
|
+
>>> xyz = [Point(2, 3, 5)]
|
|
290
|
+
>>> Point(*world_to_local_coordinates(f, xyz)[0])
|
|
291
|
+
Point(3.726, 4.088, 1.550)
|
|
292
|
+
|
|
293
|
+
"""
|
|
294
|
+
from compas.geometry import Frame # noqa: F811
|
|
295
|
+
|
|
296
|
+
T = matrix_from_change_of_basis(Frame.worldXY(), frame)
|
|
297
|
+
return transform_points(xyz, T)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def local_to_world_coordinates(frame, xyz):
|
|
301
|
+
"""Convert local coordinates to global coordinates.
|
|
302
|
+
|
|
303
|
+
Parameters
|
|
304
|
+
----------
|
|
305
|
+
frame : [point, vector, vector]
|
|
306
|
+
The local coordinate system.
|
|
307
|
+
xyz : array-like[[float, float, float] | :class:`compas.geometry.Point`]
|
|
308
|
+
The global coordinates of the points to convert.
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
list[[float, float, float]]
|
|
313
|
+
The coordinates of the given points in the local coordinate system.
|
|
314
|
+
|
|
315
|
+
Examples
|
|
316
|
+
--------
|
|
317
|
+
>>> from compas.geometry import Point, Frame
|
|
318
|
+
>>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9])
|
|
319
|
+
>>> xyz = [Point(3.726, 4.088, 1.550)]
|
|
320
|
+
>>> Point(*local_to_world_coordinates(f, xyz)[0])
|
|
321
|
+
Point(2.000, 3.000, 5.000)
|
|
322
|
+
|
|
323
|
+
"""
|
|
324
|
+
from compas.geometry import Frame # noqa: F811
|
|
325
|
+
|
|
326
|
+
T = matrix_from_change_of_basis(frame, Frame.worldXY())
|
|
327
|
+
return transform_points(xyz, T)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
# ==============================================================================
|
|
331
|
+
# translate
|
|
332
|
+
# ==============================================================================
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def translate_points(points, vector):
|
|
336
|
+
"""Translate points.
|
|
337
|
+
|
|
338
|
+
Parameters
|
|
339
|
+
----------
|
|
340
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
341
|
+
A list of points.
|
|
342
|
+
vector : [float, float, float] | :class:`compas.geometry.Vector`
|
|
343
|
+
A translation vector.
|
|
344
|
+
|
|
345
|
+
Returns
|
|
346
|
+
-------
|
|
347
|
+
list[[float, float, float]]
|
|
348
|
+
The translated points.
|
|
349
|
+
|
|
350
|
+
Examples
|
|
351
|
+
--------
|
|
352
|
+
>>>
|
|
353
|
+
|
|
354
|
+
"""
|
|
355
|
+
return [add_vectors(point, vector) for point in points]
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def translate_points_xy(points, vector):
|
|
359
|
+
"""Translate points and in the XY plane.
|
|
360
|
+
|
|
361
|
+
Parameters
|
|
362
|
+
----------
|
|
363
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
364
|
+
A list of points.
|
|
365
|
+
vector : [float, float, float] | :class:`compas.geometry.Vector`
|
|
366
|
+
A translation vector.
|
|
367
|
+
|
|
368
|
+
Returns
|
|
369
|
+
-------
|
|
370
|
+
list[[float, float, float]]
|
|
371
|
+
The translated points in the XY plane (Z=0).
|
|
372
|
+
|
|
373
|
+
Examples
|
|
374
|
+
--------
|
|
375
|
+
>>>
|
|
376
|
+
|
|
377
|
+
"""
|
|
378
|
+
return [add_vectors_xy(point, vector) for point in points]
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
# ==============================================================================
|
|
382
|
+
# scale
|
|
383
|
+
# ==============================================================================
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def scale_points(points, scale):
|
|
387
|
+
"""Scale points.
|
|
388
|
+
|
|
389
|
+
Parameters
|
|
390
|
+
----------
|
|
391
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
392
|
+
A list of points.
|
|
393
|
+
scale : float
|
|
394
|
+
A scaling factor.
|
|
395
|
+
|
|
396
|
+
Returns
|
|
397
|
+
-------
|
|
398
|
+
list[[float, float, float]]
|
|
399
|
+
The scaled points.
|
|
400
|
+
|
|
401
|
+
Examples
|
|
402
|
+
--------
|
|
403
|
+
>>>
|
|
404
|
+
|
|
405
|
+
"""
|
|
406
|
+
T = matrix_from_scale_factors([scale, scale, scale])
|
|
407
|
+
return transform_points(points, T)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def scale_points_xy(points, scale):
|
|
411
|
+
"""Scale points in the XY plane.
|
|
412
|
+
|
|
413
|
+
Parameters
|
|
414
|
+
----------
|
|
415
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
416
|
+
A list of points.
|
|
417
|
+
scale : float
|
|
418
|
+
A scaling factor.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
list[[float, float, float]]
|
|
423
|
+
The scaled points in the XY plane (Z=0).
|
|
424
|
+
|
|
425
|
+
Examples
|
|
426
|
+
--------
|
|
427
|
+
>>>
|
|
428
|
+
|
|
429
|
+
"""
|
|
430
|
+
T = matrix_from_scale_factors([scale, scale, 0])
|
|
431
|
+
return transform_points(points, T)
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
# ==============================================================================
|
|
435
|
+
# rotate
|
|
436
|
+
# ==============================================================================
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def rotate_points(points, angle, axis=None, origin=None):
|
|
440
|
+
"""Rotates points around an arbitrary axis in 3D.
|
|
441
|
+
|
|
442
|
+
Parameters
|
|
443
|
+
----------
|
|
444
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
445
|
+
A list of points.
|
|
446
|
+
angle : float
|
|
447
|
+
The angle of rotation in radians.
|
|
448
|
+
axis : [float, float, float] | :class:`compas.geometry.Vector`, optional
|
|
449
|
+
The rotation axis.
|
|
450
|
+
Default is ``[0.0, 0.0, 1.0]``
|
|
451
|
+
origin : [float, float, float] | :class:`compas.geometry.Point`, optional
|
|
452
|
+
The origin of the rotation axis.
|
|
453
|
+
Default is ``[0.0, 0.0, 0.0]``.
|
|
454
|
+
|
|
455
|
+
Returns
|
|
456
|
+
-------
|
|
457
|
+
list[[float, float, float]]
|
|
458
|
+
The rotated points
|
|
459
|
+
|
|
460
|
+
Notes
|
|
461
|
+
-----
|
|
462
|
+
For more info, see [1]_.
|
|
463
|
+
|
|
464
|
+
References
|
|
465
|
+
----------
|
|
466
|
+
.. [1] Wikipedia. *Rotation matrix*.
|
|
467
|
+
Available at: https://en.wikipedia.org/wiki/Rotation_matrix.
|
|
468
|
+
|
|
469
|
+
Examples
|
|
470
|
+
--------
|
|
471
|
+
>>>
|
|
472
|
+
|
|
473
|
+
"""
|
|
474
|
+
if axis is None:
|
|
475
|
+
axis = [0.0, 0.0, 1.0]
|
|
476
|
+
if origin is None:
|
|
477
|
+
origin = [0.0, 0.0, 0.0]
|
|
478
|
+
|
|
479
|
+
R = matrix_from_axis_and_angle(axis, angle, origin)
|
|
480
|
+
points = transform_points(points, R)
|
|
481
|
+
return points
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def rotate_points_xy(points, angle, origin=None):
|
|
485
|
+
"""Rotates points in the XY plane around the Z axis at a specific origin.
|
|
486
|
+
|
|
487
|
+
Parameters
|
|
488
|
+
----------
|
|
489
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
490
|
+
A list of points.
|
|
491
|
+
angle : float
|
|
492
|
+
The angle of rotation in radians.
|
|
493
|
+
origin : [float, float, float] | :class:`compas.geometry.Point`, optional
|
|
494
|
+
The origin of the rotation axis.
|
|
495
|
+
Default is ``[0.0, 0.0, 0.0]``.
|
|
496
|
+
|
|
497
|
+
Returns
|
|
498
|
+
-------
|
|
499
|
+
list[[float, float, 0.0]]
|
|
500
|
+
The rotated points in the XY plane (Z=0).
|
|
501
|
+
|
|
502
|
+
Examples
|
|
503
|
+
--------
|
|
504
|
+
>>>
|
|
505
|
+
|
|
506
|
+
"""
|
|
507
|
+
if not origin:
|
|
508
|
+
origin = [0.0, 0.0, 0.0]
|
|
509
|
+
|
|
510
|
+
cosa = math.cos(angle)
|
|
511
|
+
sina = math.sin(angle)
|
|
512
|
+
R = [[cosa, -sina, 0.0], [sina, cosa, 0.0], [0.0, 0.0, 1.0]]
|
|
513
|
+
# translate points
|
|
514
|
+
points = translate_points_xy(points, scale_vector_xy(origin, -1.0))
|
|
515
|
+
# rotate points
|
|
516
|
+
points = [multiply_matrix_vector(R, point) for point in points]
|
|
517
|
+
# translate points back
|
|
518
|
+
points = translate_points_xy(points, origin)
|
|
519
|
+
return points
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
# ==============================================================================
|
|
523
|
+
# mirror
|
|
524
|
+
# ==============================================================================
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def mirror_vector_vector(v1, v2):
|
|
528
|
+
"""Mirrors vector about vector.
|
|
529
|
+
|
|
530
|
+
Parameters
|
|
531
|
+
----------
|
|
532
|
+
v1 : [float, float, float] | :class:`compas.geometry.Vector`
|
|
533
|
+
The vector.
|
|
534
|
+
v2 : [float, float, float] | :class:`compas.geometry.Vector`
|
|
535
|
+
The normalized vector as mirror axis
|
|
536
|
+
|
|
537
|
+
Returns
|
|
538
|
+
-------
|
|
539
|
+
[float, float, float]
|
|
540
|
+
The mirrored vector.
|
|
541
|
+
|
|
542
|
+
Notes
|
|
543
|
+
-----
|
|
544
|
+
For more info, see [1]_.
|
|
545
|
+
|
|
546
|
+
References
|
|
547
|
+
----------
|
|
548
|
+
.. [1] Math Stack Exchange. *How to get a reflection vector?*
|
|
549
|
+
Available at: https://math.stackexchange.com/questions/13261/how-to-get-a-reflection-vector.
|
|
550
|
+
|
|
551
|
+
"""
|
|
552
|
+
return subtract_vectors(v1, scale_vector(v2, 2 * dot_vectors(v1, v2)))
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def mirror_point_point(point, mirror):
|
|
556
|
+
"""Mirror a point about a point.
|
|
557
|
+
|
|
558
|
+
Parameters
|
|
559
|
+
----------
|
|
560
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
561
|
+
XYZ coordinates of the point to mirror.
|
|
562
|
+
mirror : [float, float, float] | :class:`compas.geometry.Point`
|
|
563
|
+
XYZ coordinates of the mirror point.
|
|
564
|
+
|
|
565
|
+
Returns
|
|
566
|
+
-------
|
|
567
|
+
[float, float, float]
|
|
568
|
+
The mirrored point.
|
|
569
|
+
|
|
570
|
+
"""
|
|
571
|
+
return add_vectors(mirror, subtract_vectors(mirror, point))
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def mirror_point_point_xy(point, mirror):
|
|
575
|
+
"""Mirror a point about a point.
|
|
576
|
+
|
|
577
|
+
Parameters
|
|
578
|
+
----------
|
|
579
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
580
|
+
XY(Z) coordinates of the point to mirror.
|
|
581
|
+
mirror : [float, float, float] | :class:`compas.geometry.Point`
|
|
582
|
+
XY(Z) coordinates of the mirror point.
|
|
583
|
+
|
|
584
|
+
Returns
|
|
585
|
+
-------
|
|
586
|
+
[float, float, float]
|
|
587
|
+
The mirrored point, with Z=0.
|
|
588
|
+
|
|
589
|
+
"""
|
|
590
|
+
return add_vectors_xy(mirror, subtract_vectors_xy(mirror, point))
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def mirror_points_point(points, mirror):
|
|
594
|
+
"""Mirror multiple points about a point.
|
|
595
|
+
|
|
596
|
+
Parameters
|
|
597
|
+
----------
|
|
598
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
599
|
+
List of points.
|
|
600
|
+
mirror : [float, float, float] | :class:`compas.geometry.Point`
|
|
601
|
+
The mirror point.
|
|
602
|
+
|
|
603
|
+
Returns
|
|
604
|
+
-------
|
|
605
|
+
list[[float, float, float]]
|
|
606
|
+
The mirrored points, with Z=0.
|
|
607
|
+
|
|
608
|
+
"""
|
|
609
|
+
return [mirror_point_point(point, mirror) for point in points]
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def mirror_points_point_xy(points, mirror):
|
|
613
|
+
"""Mirror multiple points about a point.
|
|
614
|
+
|
|
615
|
+
Parameters
|
|
616
|
+
----------
|
|
617
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
618
|
+
List of points with XY(Z) coordinates.
|
|
619
|
+
mirror : [float, float, float] | :class:`compas.geometry.Point`
|
|
620
|
+
The XY(Z) coordinates of the mirror point.
|
|
621
|
+
|
|
622
|
+
Returns
|
|
623
|
+
-------
|
|
624
|
+
list[[float, float, float]]
|
|
625
|
+
The mirrored points, with Z=0.
|
|
626
|
+
|
|
627
|
+
"""
|
|
628
|
+
return [mirror_point_point_xy(point, mirror) for point in points]
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def mirror_point_line(point, line):
|
|
632
|
+
"""Mirror a point about a line.
|
|
633
|
+
|
|
634
|
+
Parameters
|
|
635
|
+
----------
|
|
636
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
637
|
+
XYZ coordinates of the point to mirror.
|
|
638
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
639
|
+
Two points defining the mirror line.
|
|
640
|
+
|
|
641
|
+
Returns
|
|
642
|
+
-------
|
|
643
|
+
[float, float, float]
|
|
644
|
+
The mirrored point.
|
|
645
|
+
|
|
646
|
+
"""
|
|
647
|
+
closest = closest_point_on_line(point, line)
|
|
648
|
+
return add_vectors(closest, subtract_vectors(closest, point))
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def mirror_point_line_xy(point, line):
|
|
652
|
+
"""Mirror a point about a line.
|
|
653
|
+
|
|
654
|
+
Parameters
|
|
655
|
+
----------
|
|
656
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
657
|
+
XY(Z) coordinates of the point to mirror.
|
|
658
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
659
|
+
Two points defining the line.
|
|
660
|
+
XY(Z) coordinates of the two points defining the mirror line.
|
|
661
|
+
|
|
662
|
+
Returns
|
|
663
|
+
-------
|
|
664
|
+
[float, float, float]
|
|
665
|
+
The mirrored point, with Z=0.
|
|
666
|
+
|
|
667
|
+
"""
|
|
668
|
+
closest = closest_point_on_line_xy(point, line)
|
|
669
|
+
return add_vectors_xy(closest, subtract_vectors_xy(closest, point))
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def mirror_points_line(points, line):
|
|
673
|
+
"""Mirror a point about a line.
|
|
674
|
+
|
|
675
|
+
Parameters
|
|
676
|
+
----------
|
|
677
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
678
|
+
List of points to mirror.
|
|
679
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
680
|
+
Two points defining the mirror line.
|
|
681
|
+
|
|
682
|
+
Returns
|
|
683
|
+
-------
|
|
684
|
+
list[[float, float, float]]
|
|
685
|
+
The mirrored points.
|
|
686
|
+
|
|
687
|
+
"""
|
|
688
|
+
return [mirror_point_line(point, line) for point in points]
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def mirror_points_line_xy(points, line):
|
|
692
|
+
"""Mirror a point about a line.
|
|
693
|
+
|
|
694
|
+
Parameters
|
|
695
|
+
----------
|
|
696
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
697
|
+
List of points to mirror.
|
|
698
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
699
|
+
Two points defining the mirror line.
|
|
700
|
+
|
|
701
|
+
Returns
|
|
702
|
+
-------
|
|
703
|
+
list[[float, float, float]]
|
|
704
|
+
The mirrored points.
|
|
705
|
+
|
|
706
|
+
"""
|
|
707
|
+
return [mirror_point_line_xy(point, line) for point in points]
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
def mirror_point_plane(point, plane):
|
|
711
|
+
"""Mirror a point about a plane.
|
|
712
|
+
|
|
713
|
+
Parameters
|
|
714
|
+
----------
|
|
715
|
+
point : list[float]
|
|
716
|
+
XYZ coordinates of mirror point.
|
|
717
|
+
plane : [point, vector]
|
|
718
|
+
Base point and normal defining the mirror plane.
|
|
719
|
+
|
|
720
|
+
Returns
|
|
721
|
+
-------
|
|
722
|
+
[float, float, float]
|
|
723
|
+
XYZ coordinates of the mirrored point.
|
|
724
|
+
|
|
725
|
+
"""
|
|
726
|
+
closest = closest_point_on_plane(point, plane)
|
|
727
|
+
return add_vectors(closest, subtract_vectors(closest, point))
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
def mirror_points_plane(points, plane):
|
|
731
|
+
"""Mirror a point about a plane.
|
|
732
|
+
|
|
733
|
+
Parameters
|
|
734
|
+
----------
|
|
735
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
736
|
+
List of points to mirror.
|
|
737
|
+
plane : [point, vector]
|
|
738
|
+
Base point and normal defining the mirror plane.
|
|
739
|
+
|
|
740
|
+
Returns
|
|
741
|
+
-------
|
|
742
|
+
list[[float, float, float]]
|
|
743
|
+
The mirrored points.
|
|
744
|
+
|
|
745
|
+
"""
|
|
746
|
+
return [mirror_point_plane(point, plane) for point in points]
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
# ==============================================================================
|
|
750
|
+
# project
|
|
751
|
+
# specify orhtogonal
|
|
752
|
+
# add perspective
|
|
753
|
+
# ==============================================================================
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
def project_point_plane(point, plane):
|
|
757
|
+
"""Project a point onto a plane.
|
|
758
|
+
|
|
759
|
+
Parameters
|
|
760
|
+
----------
|
|
761
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
762
|
+
XYZ coordinates of the point.
|
|
763
|
+
plane : [point, vector]
|
|
764
|
+
Base point and normal vector defining the projection plane.
|
|
765
|
+
|
|
766
|
+
Returns
|
|
767
|
+
-------
|
|
768
|
+
[float, float, float]
|
|
769
|
+
XYZ coordinates of the projected point.
|
|
770
|
+
|
|
771
|
+
Notes
|
|
772
|
+
-----
|
|
773
|
+
The projection is in the direction perpendicular to the plane.
|
|
774
|
+
The projected point is thus the closest point on the plane to the original
|
|
775
|
+
point [1]_.
|
|
776
|
+
|
|
777
|
+
References
|
|
778
|
+
----------
|
|
779
|
+
.. [1] Math Stack Exchange. *Project a point in 3D on a given plane*.
|
|
780
|
+
Available at: https://math.stackexchange.com/questions/444968/project-a-point-in-3d-on-a-given-plane.
|
|
781
|
+
|
|
782
|
+
Examples
|
|
783
|
+
--------
|
|
784
|
+
>>> from compas.geometry import project_point_plane
|
|
785
|
+
>>> point = [3.0, 3.0, 3.0]
|
|
786
|
+
>>> plane = ([0.0, 0.0, 0.0], [0.0, 0.0, 1.0]) # the XY plane
|
|
787
|
+
>>> project_point_plane(point, plane)
|
|
788
|
+
[3.0, 3.0, 0.0]
|
|
789
|
+
|
|
790
|
+
"""
|
|
791
|
+
base, normal = plane
|
|
792
|
+
normal = normalize_vector(normal)
|
|
793
|
+
vector = subtract_vectors(point, base)
|
|
794
|
+
snormal = scale_vector(normal, dot_vectors(vector, normal))
|
|
795
|
+
return subtract_vectors(point, snormal)
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
def project_points_plane(points, plane):
|
|
799
|
+
"""Project multiple points onto a plane.
|
|
800
|
+
|
|
801
|
+
Parameters
|
|
802
|
+
----------
|
|
803
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
804
|
+
List of points.
|
|
805
|
+
plane : [point, vector]
|
|
806
|
+
Base point and normal vector defining the projection plane.
|
|
807
|
+
|
|
808
|
+
Returns
|
|
809
|
+
-------
|
|
810
|
+
list[[float, float, float]]
|
|
811
|
+
The projected points.
|
|
812
|
+
|
|
813
|
+
See Also
|
|
814
|
+
--------
|
|
815
|
+
project_point_plane
|
|
816
|
+
|
|
817
|
+
"""
|
|
818
|
+
return [project_point_plane(point, plane) for point in points]
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
def project_point_line(point, line):
|
|
822
|
+
"""Project a point onto a line.
|
|
823
|
+
|
|
824
|
+
Parameters
|
|
825
|
+
----------
|
|
826
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
827
|
+
XYZ coordinates of the point.
|
|
828
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
829
|
+
Two points defining the projection line.
|
|
830
|
+
|
|
831
|
+
Returns
|
|
832
|
+
-------
|
|
833
|
+
[float, float, float]
|
|
834
|
+
XYZ coordinates of the projected point.
|
|
835
|
+
|
|
836
|
+
Notes
|
|
837
|
+
-----
|
|
838
|
+
For more info, see [1]_.
|
|
839
|
+
|
|
840
|
+
References
|
|
841
|
+
----------
|
|
842
|
+
.. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*.
|
|
843
|
+
Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line.
|
|
844
|
+
|
|
845
|
+
"""
|
|
846
|
+
a, b = line
|
|
847
|
+
ab = subtract_vectors(b, a)
|
|
848
|
+
ap = subtract_vectors(point, a)
|
|
849
|
+
c = vector_component(ap, ab)
|
|
850
|
+
|
|
851
|
+
return add_vectors(a, c)
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def project_point_line_xy(point, line):
|
|
855
|
+
"""Project a point onto a line in the XY plane.
|
|
856
|
+
|
|
857
|
+
Parameters
|
|
858
|
+
----------
|
|
859
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
860
|
+
XY(Z) coordinates of the point.
|
|
861
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
862
|
+
Two points defining the projection line.
|
|
863
|
+
|
|
864
|
+
Returns
|
|
865
|
+
-------
|
|
866
|
+
[float, float, float]
|
|
867
|
+
XYZ coordinates of the projected point, with Z=0.
|
|
868
|
+
|
|
869
|
+
Notes
|
|
870
|
+
-----
|
|
871
|
+
For more info, see [1]_.
|
|
872
|
+
|
|
873
|
+
References
|
|
874
|
+
----------
|
|
875
|
+
.. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*.
|
|
876
|
+
Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line.
|
|
877
|
+
|
|
878
|
+
"""
|
|
879
|
+
a, b = line
|
|
880
|
+
ab = subtract_vectors_xy(b, a)
|
|
881
|
+
ap = subtract_vectors_xy(point, a)
|
|
882
|
+
c = vector_component_xy(ap, ab)
|
|
883
|
+
return add_vectors_xy(a, c)
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def project_points_line(points, line):
|
|
887
|
+
"""Project points onto a line.
|
|
888
|
+
|
|
889
|
+
Parameters
|
|
890
|
+
----------
|
|
891
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
892
|
+
XYZ coordinates of the points.
|
|
893
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
894
|
+
Two points defining the projection line.
|
|
895
|
+
|
|
896
|
+
Returns
|
|
897
|
+
-------
|
|
898
|
+
list[[float, float, float]]
|
|
899
|
+
XYZ coordinates of the projected points.
|
|
900
|
+
|
|
901
|
+
Notes
|
|
902
|
+
-----
|
|
903
|
+
For more info, see [1]_.
|
|
904
|
+
|
|
905
|
+
References
|
|
906
|
+
----------
|
|
907
|
+
.. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*.
|
|
908
|
+
Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line.
|
|
909
|
+
|
|
910
|
+
"""
|
|
911
|
+
return [project_point_line(point, line) for point in points]
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
def project_points_line_xy(points, line):
|
|
915
|
+
"""Project points onto a line in the XY plane.
|
|
916
|
+
|
|
917
|
+
Parameters
|
|
918
|
+
----------
|
|
919
|
+
point : [float, float, float] | :class:`compas.geometry.Point`
|
|
920
|
+
XY(Z) coordinates of the point.
|
|
921
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
922
|
+
Two points defining the projection line.
|
|
923
|
+
|
|
924
|
+
Returns
|
|
925
|
+
-------
|
|
926
|
+
[float, float, float]
|
|
927
|
+
XYZ coordinates of the projected point, with Z=0.
|
|
928
|
+
|
|
929
|
+
Notes
|
|
930
|
+
-----
|
|
931
|
+
For more info, see [1]_.
|
|
932
|
+
|
|
933
|
+
References
|
|
934
|
+
----------
|
|
935
|
+
.. [1] Wiki Books. *Linear Algebra/Orthogonal Projection Onto a Line*.
|
|
936
|
+
Available at: https://en.wikibooks.org/wiki/Linear_Algebra/Orthogonal_Projection_Onto_a_Line.
|
|
937
|
+
|
|
938
|
+
"""
|
|
939
|
+
return [project_point_line_xy(point, line) for point in points]
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
# ==============================================================================
|
|
943
|
+
# reflection
|
|
944
|
+
# ==============================================================================
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def reflect_line_plane(line, plane, tol=None):
|
|
948
|
+
"""Bounce a line of a reflection plane.
|
|
949
|
+
|
|
950
|
+
Parameters
|
|
951
|
+
----------
|
|
952
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
953
|
+
Two points defining the line.
|
|
954
|
+
plane : [point, vector]
|
|
955
|
+
Base point and normal vector of the plane.
|
|
956
|
+
tol : float, optional
|
|
957
|
+
A tolerance for finding the intersection between the line and the plane.
|
|
958
|
+
Default is :func:`TOL.absolute`.
|
|
959
|
+
|
|
960
|
+
Returns
|
|
961
|
+
-------
|
|
962
|
+
tuple[[float, float, float], [float, float, float]]
|
|
963
|
+
The reflected line defined by the intersection point of the line and plane
|
|
964
|
+
and the mirrored start point of the line with respect to a line perpendicular
|
|
965
|
+
to the plane through the intersection.
|
|
966
|
+
|
|
967
|
+
Notes
|
|
968
|
+
-----
|
|
969
|
+
The direction of the line and plane are important.
|
|
970
|
+
The line is only reflected if it points towards the front of the plane.
|
|
971
|
+
This is true if the dot product of the direction vector of the line and the
|
|
972
|
+
normal vector of the plane is smaller than zero.
|
|
973
|
+
|
|
974
|
+
Examples
|
|
975
|
+
--------
|
|
976
|
+
>>> plane = [0, 0, 0], [0, 1, 0]
|
|
977
|
+
>>> line = [-1, 1, 0], [-0.5, 0.5, 0]
|
|
978
|
+
>>> reflect_line_plane(line, plane)
|
|
979
|
+
([0.0, 0.0, 0.0], [1.0, 1.0, 0.0])
|
|
980
|
+
|
|
981
|
+
"""
|
|
982
|
+
from compas.geometry import intersection_line_plane
|
|
983
|
+
|
|
984
|
+
x = intersection_line_plane(line, plane, tol=tol)
|
|
985
|
+
if not x:
|
|
986
|
+
return
|
|
987
|
+
|
|
988
|
+
a, b = line
|
|
989
|
+
o, n = plane
|
|
990
|
+
ab = subtract_vectors(b, a)
|
|
991
|
+
|
|
992
|
+
if dot_vectors(ab, n) > 0:
|
|
993
|
+
# the line does not point towards the front of the plane
|
|
994
|
+
return
|
|
995
|
+
|
|
996
|
+
mirror = x, add_vectors(x, n)
|
|
997
|
+
return x, mirror_point_line(a, mirror)
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
def reflect_line_triangle(line, triangle, tol=None):
|
|
1001
|
+
"""Bounce a line of a reflection triangle.
|
|
1002
|
+
|
|
1003
|
+
Parameters
|
|
1004
|
+
----------
|
|
1005
|
+
line : [point, point] | :class:`compas.geometry.Line`
|
|
1006
|
+
Two points defining the line.
|
|
1007
|
+
triangle : [point, point, point]
|
|
1008
|
+
The triangle vertices.
|
|
1009
|
+
tol : float, optional
|
|
1010
|
+
A tolerance value for finding the intersection between the line and the triangle.
|
|
1011
|
+
Default is :func:`TOL.absolute`.
|
|
1012
|
+
|
|
1013
|
+
Returns
|
|
1014
|
+
-------
|
|
1015
|
+
tuple[[float, float, float], [float, float, float]]
|
|
1016
|
+
The reflected line defined by the intersection point of the line and triangle
|
|
1017
|
+
and the mirrored start point of the line with respect to a line perpendicular
|
|
1018
|
+
to the triangle through the intersection.
|
|
1019
|
+
|
|
1020
|
+
Notes
|
|
1021
|
+
-----
|
|
1022
|
+
The direction of the line and triangle are important.
|
|
1023
|
+
The line is only reflected if it points towards the front of the triangle.
|
|
1024
|
+
This is true if the dot product of the direction vector of the line and the
|
|
1025
|
+
normal vector of the triangle is smaller than zero.
|
|
1026
|
+
|
|
1027
|
+
Examples
|
|
1028
|
+
--------
|
|
1029
|
+
>>> triangle = [1.0, 0, 0], [-1.0, 0, 0], [0, 0, 1.0]
|
|
1030
|
+
>>> line = [-1, 1, 0], [-0.5, 0.5, 0]
|
|
1031
|
+
>>> reflect_line_triangle(line, triangle)
|
|
1032
|
+
([0.0, 0.0, 0.0], [1.0, 1.0, 0.0])
|
|
1033
|
+
|
|
1034
|
+
"""
|
|
1035
|
+
from compas.geometry import intersection_line_triangle
|
|
1036
|
+
|
|
1037
|
+
x = intersection_line_triangle(line, triangle, tol=tol)
|
|
1038
|
+
if not x:
|
|
1039
|
+
return
|
|
1040
|
+
|
|
1041
|
+
a, b = line
|
|
1042
|
+
t1, t2, t3 = triangle
|
|
1043
|
+
ab = subtract_vectors(b, a)
|
|
1044
|
+
n = cross_vectors(subtract_vectors(t2, t1), subtract_vectors(t3, t1))
|
|
1045
|
+
|
|
1046
|
+
if dot_vectors(ab, n) > 0:
|
|
1047
|
+
# the line does not point towards the front of the triangle
|
|
1048
|
+
return
|
|
1049
|
+
|
|
1050
|
+
mirror = x, add_vectors(x, n)
|
|
1051
|
+
return x, mirror_point_line(a, mirror)
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
# ==============================================================================
|
|
1055
|
+
# shear
|
|
1056
|
+
# ==============================================================================
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
# ==============================================================================
|
|
1060
|
+
# orientation
|
|
1061
|
+
# ==============================================================================
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
def orient_points(points, reference_plane, target_plane):
|
|
1065
|
+
"""Orient points from one plane to another.
|
|
1066
|
+
|
|
1067
|
+
Parameters
|
|
1068
|
+
----------
|
|
1069
|
+
points : sequence[[float, float, float] | :class:`compas.geometry.Point`]
|
|
1070
|
+
XYZ coordinates of the points.
|
|
1071
|
+
reference_plane : [point, vector]
|
|
1072
|
+
Base point and normal defining a reference plane.
|
|
1073
|
+
target_plane : [point, vector]
|
|
1074
|
+
Base point and normal defining a target plane.
|
|
1075
|
+
|
|
1076
|
+
Returns
|
|
1077
|
+
-------
|
|
1078
|
+
list[[float, float, float]]
|
|
1079
|
+
XYZ coordinates of the oriented points.
|
|
1080
|
+
|
|
1081
|
+
Notes
|
|
1082
|
+
-----
|
|
1083
|
+
This function is useful to orient a planar problem in the xy-plane to simplify
|
|
1084
|
+
the calculation (see example).
|
|
1085
|
+
|
|
1086
|
+
Examples
|
|
1087
|
+
--------
|
|
1088
|
+
>>> from compas.geometry import Point
|
|
1089
|
+
>>> from compas.geometry import orient_points
|
|
1090
|
+
>>> from compas.geometry import intersection_segment_segment_xy
|
|
1091
|
+
|
|
1092
|
+
>>> refplane = ([0.57735, 0.57735, 0.57735], [1.0, 1.0, 1.0])
|
|
1093
|
+
>>> tarplane = ([0.0, 0.0, 0.0], [0.0, 0.0, 1.0])
|
|
1094
|
+
>>> points = [\
|
|
1095
|
+
[0.288675, 0.288675, 1.1547],\
|
|
1096
|
+
[0.866025, 0.866025, 0.0],\
|
|
1097
|
+
[1.077350, 0.077350, 0.57735],\
|
|
1098
|
+
[0.077350, 1.077350, 0.57735]\
|
|
1099
|
+
]
|
|
1100
|
+
|
|
1101
|
+
>>> points = orient_points(points, refplane, tarplane)
|
|
1102
|
+
>>> ab = points[0], points[1]
|
|
1103
|
+
>>> cd = points[2], points[3]
|
|
1104
|
+
>>> point = intersection_segment_segment_xy(ab, cd)
|
|
1105
|
+
>>> points = orient_points([point], tarplane, refplane)
|
|
1106
|
+
|
|
1107
|
+
>>> Point(*points[0])
|
|
1108
|
+
Point(0.577, 0.577, 0.577)
|
|
1109
|
+
|
|
1110
|
+
"""
|
|
1111
|
+
axis = cross_vectors(reference_plane[1], target_plane[1])
|
|
1112
|
+
angle = angle_vectors(reference_plane[1], target_plane[1])
|
|
1113
|
+
origin = reference_plane[0]
|
|
1114
|
+
|
|
1115
|
+
if angle:
|
|
1116
|
+
points = rotate_points(points, angle, axis, origin)
|
|
1117
|
+
|
|
1118
|
+
vector = subtract_vectors(target_plane[0], reference_plane[0])
|
|
1119
|
+
points = translate_points(points, vector)
|
|
1120
|
+
|
|
1121
|
+
return points
|