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,544 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from sys import float_info
|
|
7
|
+
|
|
8
|
+
from compas.geometry import Geometry
|
|
9
|
+
from compas.geometry import Rotation
|
|
10
|
+
from compas.geometry import quaternion_canonize
|
|
11
|
+
from compas.geometry import quaternion_conjugate
|
|
12
|
+
from compas.geometry import quaternion_from_matrix
|
|
13
|
+
from compas.geometry import quaternion_is_unit
|
|
14
|
+
from compas.geometry import quaternion_multiply
|
|
15
|
+
from compas.geometry import quaternion_norm
|
|
16
|
+
from compas.geometry import quaternion_unitize
|
|
17
|
+
from compas.tolerance import TOL
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Quaternion(Geometry):
|
|
21
|
+
r"""A quaternion is defined by 4 components, X, Y, Z, and W.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
w : float
|
|
26
|
+
The scalar (real) part of a quaternion.
|
|
27
|
+
x : float
|
|
28
|
+
X component of the vector (complex, imaginary) part of a quaternion.
|
|
29
|
+
y : float
|
|
30
|
+
Y component of the vector (complex, imaginary) part of a quaternion.
|
|
31
|
+
z : float
|
|
32
|
+
Z component of the vector (complex, imaginary) part of a quaternion.
|
|
33
|
+
name : str, optional
|
|
34
|
+
The name of the transformation.
|
|
35
|
+
|
|
36
|
+
Attributes
|
|
37
|
+
----------
|
|
38
|
+
w : float
|
|
39
|
+
The W component of the quaternion.
|
|
40
|
+
x : float
|
|
41
|
+
The X component of the quaternion.
|
|
42
|
+
y : float
|
|
43
|
+
The Y component of the quaternion.
|
|
44
|
+
z : float
|
|
45
|
+
The Z component of the quaternion.
|
|
46
|
+
wxyz : list[float], read-only
|
|
47
|
+
Quaternion as a list of float in the 'wxyz' convention.
|
|
48
|
+
xyzw : list[float], read-only
|
|
49
|
+
Quaternion as a list of float in the 'xyzw' convention.
|
|
50
|
+
norm : float, read-only
|
|
51
|
+
The length (euclidean norm) of the quaternion.
|
|
52
|
+
is_unit : bool, read-only
|
|
53
|
+
True if the quaternion is unit-length.
|
|
54
|
+
False otherwise.
|
|
55
|
+
|
|
56
|
+
Notes
|
|
57
|
+
-----
|
|
58
|
+
The default convention to represent a quaternion :math:`q` in this module
|
|
59
|
+
is by four real values :math:`w`, :math:`x`, :math:`y`, :math:`z`.
|
|
60
|
+
The first value :math:`w` is the scalar (real) part,
|
|
61
|
+
and :math:`x`, :math:`y`, :math:`z` form the vector (complex, imaginary) part [1]_, so that:
|
|
62
|
+
|
|
63
|
+
.. math::
|
|
64
|
+
|
|
65
|
+
q = w + xi + yj + zk
|
|
66
|
+
|
|
67
|
+
where :math:`i, j, k` are basis components with following multiplication rules [2]_:
|
|
68
|
+
|
|
69
|
+
.. math::
|
|
70
|
+
|
|
71
|
+
\begin{align}
|
|
72
|
+
ii &= jj = kk = ijk = -1 \\
|
|
73
|
+
ij &= k, \quad ji = -k \\
|
|
74
|
+
jk &= i, \quad kj = -i \\
|
|
75
|
+
ki &= j, \quad ik = -j
|
|
76
|
+
\end{align}
|
|
77
|
+
|
|
78
|
+
Quaternions are associative but not commutative.
|
|
79
|
+
|
|
80
|
+
**Quaternion as rotation.**
|
|
81
|
+
|
|
82
|
+
A rotation through an angle :math:`\theta` around an axis
|
|
83
|
+
defined by a euclidean unit vector :math:`u = u_{x}i + u_{y}j + u_{z}k`
|
|
84
|
+
can be represented as a quaternion:
|
|
85
|
+
|
|
86
|
+
.. math::
|
|
87
|
+
|
|
88
|
+
q = cos(\frac{\theta}{2}) + sin(\frac{\theta}{2}) [u_{x}i + u_{y}j + u_{z}k]
|
|
89
|
+
|
|
90
|
+
i.e.:
|
|
91
|
+
|
|
92
|
+
.. math::
|
|
93
|
+
|
|
94
|
+
\begin{align}
|
|
95
|
+
w &= cos(\frac{\theta}{2}) \\
|
|
96
|
+
x &= sin(\frac{\theta}{2}) u_{x} \\
|
|
97
|
+
y &= sin(\frac{\theta}{2}) u_{y} \\
|
|
98
|
+
z &= sin(\frac{\theta}{2}) u_{z}
|
|
99
|
+
\end{align}
|
|
100
|
+
|
|
101
|
+
For a quaternion to represent a rotation or orientation, it must be unit-length.
|
|
102
|
+
A quaternion representing a rotation :math:`p` resulting from applying a rotation
|
|
103
|
+
:math:`r` to a rotation :math:`q`, i.e.: :math:`p = rq`,
|
|
104
|
+
is also unit-length.
|
|
105
|
+
|
|
106
|
+
References
|
|
107
|
+
----------
|
|
108
|
+
.. [1] http://mathworld.wolfram.com/Quaternion.html
|
|
109
|
+
.. [2] http://mathworld.wolfram.com/HamiltonsRules.html
|
|
110
|
+
.. [3] https://github.com/matthew-brett/transforms3d/blob/master/transforms3d/quaternions.py
|
|
111
|
+
|
|
112
|
+
Examples
|
|
113
|
+
--------
|
|
114
|
+
>>> Q = Quaternion(1.0, 1.0, 1.0, 1.0).unitized()
|
|
115
|
+
>>> R = Quaternion(0.0,-0.1, 0.2,-0.3).unitized()
|
|
116
|
+
>>> P = R*Q
|
|
117
|
+
>>> P.is_unit
|
|
118
|
+
True
|
|
119
|
+
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
DATASCHEMA = {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"properties": {
|
|
125
|
+
"w": {"type": "number"},
|
|
126
|
+
"x": {"type": "number"},
|
|
127
|
+
"y": {"type": "number"},
|
|
128
|
+
"z": {"type": "number"},
|
|
129
|
+
},
|
|
130
|
+
"required": ["w", "x", "y", "z"],
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def __data__(self):
|
|
135
|
+
return {"w": self.w, "x": self.x, "y": self.y, "z": self.z}
|
|
136
|
+
|
|
137
|
+
def __init__(self, w, x, y, z, name=None):
|
|
138
|
+
super(Quaternion, self).__init__(name=name)
|
|
139
|
+
self._w = None
|
|
140
|
+
self._x = None
|
|
141
|
+
self._y = None
|
|
142
|
+
self._z = None
|
|
143
|
+
self.w = w
|
|
144
|
+
self.x = x
|
|
145
|
+
self.y = y
|
|
146
|
+
self.z = z
|
|
147
|
+
|
|
148
|
+
def __repr__(self):
|
|
149
|
+
return "{0}({1}, {2}, {3}, {4})".format(type(self).__name__, self.w, self.x, self.y, self.z)
|
|
150
|
+
|
|
151
|
+
def __eq__(self, other, tol=None):
|
|
152
|
+
if not hasattr(other, "__iter__") or not hasattr(other, "__len__") or len(self) != len(other):
|
|
153
|
+
return False
|
|
154
|
+
return TOL.is_allclose(self, other, rtol=0, atol=tol)
|
|
155
|
+
|
|
156
|
+
def __getitem__(self, key):
|
|
157
|
+
if key == 0:
|
|
158
|
+
return self.w
|
|
159
|
+
if key == 1:
|
|
160
|
+
return self.x
|
|
161
|
+
if key == 2:
|
|
162
|
+
return self.y
|
|
163
|
+
if key == 3:
|
|
164
|
+
return self.z
|
|
165
|
+
raise KeyError(key)
|
|
166
|
+
|
|
167
|
+
def __setitem__(self, key, value):
|
|
168
|
+
if key == 0:
|
|
169
|
+
self.w = value
|
|
170
|
+
return
|
|
171
|
+
if key == 1:
|
|
172
|
+
self.x = value
|
|
173
|
+
return
|
|
174
|
+
if key == 2:
|
|
175
|
+
self.y = value
|
|
176
|
+
return
|
|
177
|
+
if key == 3:
|
|
178
|
+
self.z = value
|
|
179
|
+
return
|
|
180
|
+
raise KeyError(key)
|
|
181
|
+
|
|
182
|
+
def __iter__(self):
|
|
183
|
+
return iter(self.wxyz)
|
|
184
|
+
|
|
185
|
+
def __len__(self):
|
|
186
|
+
return 4
|
|
187
|
+
|
|
188
|
+
# ==========================================================================
|
|
189
|
+
# Properties
|
|
190
|
+
# ==========================================================================
|
|
191
|
+
|
|
192
|
+
@property
|
|
193
|
+
def w(self):
|
|
194
|
+
return self._w
|
|
195
|
+
|
|
196
|
+
@w.setter
|
|
197
|
+
def w(self, w):
|
|
198
|
+
self._w = float(w)
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
def x(self):
|
|
202
|
+
return self._x
|
|
203
|
+
|
|
204
|
+
@x.setter
|
|
205
|
+
def x(self, x):
|
|
206
|
+
self._x = float(x)
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def y(self):
|
|
210
|
+
return self._y
|
|
211
|
+
|
|
212
|
+
@y.setter
|
|
213
|
+
def y(self, y):
|
|
214
|
+
self._y = float(y)
|
|
215
|
+
|
|
216
|
+
@property
|
|
217
|
+
def z(self):
|
|
218
|
+
return self._z
|
|
219
|
+
|
|
220
|
+
@z.setter
|
|
221
|
+
def z(self, z):
|
|
222
|
+
self._z = float(z)
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def wxyz(self):
|
|
226
|
+
return [self.w, self.x, self.y, self.z]
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def xyzw(self):
|
|
230
|
+
return [self.x, self.y, self.z, self.w]
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def norm(self):
|
|
234
|
+
return quaternion_norm(self)
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def is_unit(self):
|
|
238
|
+
return quaternion_is_unit(self)
|
|
239
|
+
|
|
240
|
+
# ==========================================================================
|
|
241
|
+
# Operators
|
|
242
|
+
# ==========================================================================
|
|
243
|
+
|
|
244
|
+
def __mul__(self, other):
|
|
245
|
+
"""Multiply operator for two quaternions.
|
|
246
|
+
|
|
247
|
+
Parameters
|
|
248
|
+
----------
|
|
249
|
+
other : [float, float, float, float] | :class:`compas.geometry.Quaternion`
|
|
250
|
+
A Quaternion.
|
|
251
|
+
|
|
252
|
+
Returns
|
|
253
|
+
-------
|
|
254
|
+
:class:`compas.geometry.Quaternion`
|
|
255
|
+
The product :math:`P = R * Q` of this quaternion (R) multiplied by other quaternion (Q).
|
|
256
|
+
|
|
257
|
+
Notes
|
|
258
|
+
-----
|
|
259
|
+
Multiplication of two quaternions :math:`R * Q` can be interpreted as applying rotation R to an orientation Q,
|
|
260
|
+
provided that both R and Q are unit-length.
|
|
261
|
+
The result is also unit-length.
|
|
262
|
+
Multiplication of quaternions is not commutative!
|
|
263
|
+
|
|
264
|
+
Examples
|
|
265
|
+
--------
|
|
266
|
+
>>> Q = Quaternion(1.0, 1.0, 1.0, 1.0).unitized()
|
|
267
|
+
>>> R = Quaternion(0.0, -0.1, 0.2, -0.3).unitized()
|
|
268
|
+
>>> P = R * Q
|
|
269
|
+
>>> P.is_unit
|
|
270
|
+
True
|
|
271
|
+
|
|
272
|
+
"""
|
|
273
|
+
p = quaternion_multiply(list(self), list(other))
|
|
274
|
+
return Quaternion(*p)
|
|
275
|
+
|
|
276
|
+
# ==========================================================================
|
|
277
|
+
# Constructors
|
|
278
|
+
# ==========================================================================
|
|
279
|
+
|
|
280
|
+
@classmethod
|
|
281
|
+
def from_frame(cls, frame):
|
|
282
|
+
"""Creates a quaternion object from a frame.
|
|
283
|
+
|
|
284
|
+
Parameters
|
|
285
|
+
----------
|
|
286
|
+
frame : :class:`compas.geometry.Frame`
|
|
287
|
+
|
|
288
|
+
Returns
|
|
289
|
+
-------
|
|
290
|
+
:class:`compas.geometry.Quaternion`
|
|
291
|
+
The new quaternion.
|
|
292
|
+
|
|
293
|
+
Examples
|
|
294
|
+
--------
|
|
295
|
+
>>> from compas.tolerance import TOL
|
|
296
|
+
>>> from compas.geometry import Frame
|
|
297
|
+
>>> q = [1.0, -2.0, 3.0, -4.0]
|
|
298
|
+
>>> F = Frame.from_quaternion(q)
|
|
299
|
+
>>> Q = Quaternion.from_frame(F)
|
|
300
|
+
>>> TOL.is_allclose(Q.canonized(), quaternion_canonize(quaternion_unitize(q)))
|
|
301
|
+
True
|
|
302
|
+
|
|
303
|
+
"""
|
|
304
|
+
w, x, y, z = frame.quaternion
|
|
305
|
+
return cls(w, x, y, z)
|
|
306
|
+
|
|
307
|
+
@classmethod
|
|
308
|
+
def from_matrix(cls, M):
|
|
309
|
+
"""Create a Quaternion from a transformation matrix.
|
|
310
|
+
|
|
311
|
+
Parameters
|
|
312
|
+
----------
|
|
313
|
+
M : list[list[float]]
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
:class:`compas.geometry.Quaternion`
|
|
318
|
+
The new quaternion.
|
|
319
|
+
|
|
320
|
+
Examples
|
|
321
|
+
--------
|
|
322
|
+
>>> from compas.geometry import matrix_from_euler_angles
|
|
323
|
+
>>> ea = [0.2, 0.6, 0.2]
|
|
324
|
+
>>> M = matrix_from_euler_angles(ea)
|
|
325
|
+
>>> Quaternion.from_matrix(M)
|
|
326
|
+
Quaternion(0.949, 0.066, 0.302, 0.066)
|
|
327
|
+
|
|
328
|
+
"""
|
|
329
|
+
return cls(*quaternion_from_matrix(M))
|
|
330
|
+
|
|
331
|
+
@classmethod
|
|
332
|
+
def from_rotation(cls, R):
|
|
333
|
+
"""Create a Quaternion from a Rotatation.
|
|
334
|
+
|
|
335
|
+
Parameters
|
|
336
|
+
----------
|
|
337
|
+
R : :class:`compas.geometry.Rotation`
|
|
338
|
+
|
|
339
|
+
Returns
|
|
340
|
+
-------
|
|
341
|
+
:class:`compas.geometry.Quaternion`
|
|
342
|
+
The new quaternion.
|
|
343
|
+
|
|
344
|
+
Examples
|
|
345
|
+
--------
|
|
346
|
+
>>> from compas.geometry import Frame, Rotation
|
|
347
|
+
>>> R = Rotation.from_frame(Frame.worldYZ())
|
|
348
|
+
>>> Quaternion.from_rotation(R)
|
|
349
|
+
Quaternion(0.500, 0.500, 0.500, 0.500)
|
|
350
|
+
|
|
351
|
+
"""
|
|
352
|
+
return cls.from_matrix(R.matrix)
|
|
353
|
+
|
|
354
|
+
# ==========================================================================
|
|
355
|
+
# Methods
|
|
356
|
+
# ==========================================================================
|
|
357
|
+
|
|
358
|
+
def unitize(self):
|
|
359
|
+
"""Scales the quaternion to make it unit-length.
|
|
360
|
+
|
|
361
|
+
Returns
|
|
362
|
+
-------
|
|
363
|
+
None
|
|
364
|
+
|
|
365
|
+
Examples
|
|
366
|
+
--------
|
|
367
|
+
>>> q = Quaternion(1.0, 1.0, 1.0, 1.0)
|
|
368
|
+
>>> q.is_unit
|
|
369
|
+
False
|
|
370
|
+
>>> q.unitize()
|
|
371
|
+
>>> q.is_unit
|
|
372
|
+
True
|
|
373
|
+
|
|
374
|
+
"""
|
|
375
|
+
qu = quaternion_unitize(list(self))
|
|
376
|
+
self.w, self.x, self.y, self.z = qu
|
|
377
|
+
|
|
378
|
+
def unitized(self):
|
|
379
|
+
"""Returns a quaternion with a unit-length.
|
|
380
|
+
|
|
381
|
+
Returns
|
|
382
|
+
-------
|
|
383
|
+
:class:`compas.geometry.Quaternion`
|
|
384
|
+
|
|
385
|
+
Examples
|
|
386
|
+
--------
|
|
387
|
+
>>> q = Quaternion(1.0, 1.0, 1.0, 1.0)
|
|
388
|
+
>>> q.is_unit
|
|
389
|
+
False
|
|
390
|
+
>>> p = q.unitized()
|
|
391
|
+
>>> p.is_unit
|
|
392
|
+
True
|
|
393
|
+
|
|
394
|
+
"""
|
|
395
|
+
qu = quaternion_unitize(list(self))
|
|
396
|
+
return Quaternion(*qu)
|
|
397
|
+
|
|
398
|
+
def canonize(self):
|
|
399
|
+
"""Makes the quaternion canonic.
|
|
400
|
+
|
|
401
|
+
Returns
|
|
402
|
+
-------
|
|
403
|
+
None
|
|
404
|
+
|
|
405
|
+
Examples
|
|
406
|
+
--------
|
|
407
|
+
>>> from compas.geometry import Frame
|
|
408
|
+
>>> q = Quaternion.from_frame(Frame.worldZX())
|
|
409
|
+
>>> q
|
|
410
|
+
Quaternion(-0.500, 0.500, 0.500, 0.500)
|
|
411
|
+
>>> q.canonize()
|
|
412
|
+
>>> q
|
|
413
|
+
Quaternion(0.500, -0.500, -0.500, -0.500)
|
|
414
|
+
|
|
415
|
+
"""
|
|
416
|
+
qc = quaternion_canonize(list(self))
|
|
417
|
+
self.w, self.x, self.y, self.z = qc # type: ignore
|
|
418
|
+
|
|
419
|
+
def canonized(self):
|
|
420
|
+
"""Returns a quaternion in canonic form.
|
|
421
|
+
|
|
422
|
+
Returns
|
|
423
|
+
-------
|
|
424
|
+
:class:`compas.geometry.Quaternion`
|
|
425
|
+
A quaternion in canonic form.
|
|
426
|
+
|
|
427
|
+
Examples
|
|
428
|
+
--------
|
|
429
|
+
>>> from compas.geometry import Frame
|
|
430
|
+
>>> q = Quaternion.from_frame(Frame.worldZX())
|
|
431
|
+
>>> q
|
|
432
|
+
Quaternion(-0.500, 0.500, 0.500, 0.500)
|
|
433
|
+
>>> p = q.canonized()
|
|
434
|
+
>>> p
|
|
435
|
+
Quaternion(0.500, -0.500, -0.500, -0.500)
|
|
436
|
+
|
|
437
|
+
"""
|
|
438
|
+
qc = quaternion_canonize(list(self))
|
|
439
|
+
return Quaternion(*qc) # type: ignore
|
|
440
|
+
|
|
441
|
+
def conjugate(self):
|
|
442
|
+
"""Conjugate the quaternion.
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
None
|
|
447
|
+
|
|
448
|
+
Examples
|
|
449
|
+
--------
|
|
450
|
+
>>> q = Quaternion(1.0, 1.0, 1.0, 1.0)
|
|
451
|
+
>>> q.conjugate()
|
|
452
|
+
>>> q
|
|
453
|
+
Quaternion(1.000, -1.000, -1.000, -1.000)
|
|
454
|
+
|
|
455
|
+
"""
|
|
456
|
+
qc = quaternion_conjugate(list(self))
|
|
457
|
+
self.w, self.x, self.y, self.z = qc
|
|
458
|
+
|
|
459
|
+
def conjugated(self):
|
|
460
|
+
"""Returns a conjugate quaternion.
|
|
461
|
+
|
|
462
|
+
Returns
|
|
463
|
+
-------
|
|
464
|
+
:class:`compas.geometry.Quaternion`
|
|
465
|
+
The conjugated quaternion.
|
|
466
|
+
|
|
467
|
+
Examples
|
|
468
|
+
--------
|
|
469
|
+
>>> q = Quaternion(1.0, 1.0, 1.0, 1.0)
|
|
470
|
+
>>> p = q.conjugated()
|
|
471
|
+
>>> q
|
|
472
|
+
Quaternion(1.000, 1.000, 1.000, 1.000)
|
|
473
|
+
>>> p
|
|
474
|
+
Quaternion(1.000, -1.000, -1.000, -1.000)
|
|
475
|
+
|
|
476
|
+
"""
|
|
477
|
+
qc = quaternion_conjugate(list(self))
|
|
478
|
+
return Quaternion(*qc)
|
|
479
|
+
|
|
480
|
+
def dot(self, other):
|
|
481
|
+
"""Computes the cosine of the angle between the two quaternions"""
|
|
482
|
+
return self.w * other.w + self.x * other.x + self.y * other.y + self.z * other.z
|
|
483
|
+
|
|
484
|
+
def slerp(self, other, t):
|
|
485
|
+
"""Slerp: spherical interpolation of two quaternions.
|
|
486
|
+
|
|
487
|
+
Parameters
|
|
488
|
+
----------
|
|
489
|
+
other : :class:`compas.geometry.Quaternion`
|
|
490
|
+
The other quaternion to interpolate between.
|
|
491
|
+
t : float
|
|
492
|
+
A parameter in the range [0-1].
|
|
493
|
+
|
|
494
|
+
Returns
|
|
495
|
+
-------
|
|
496
|
+
:class:`compas.geometry.Quaternion`
|
|
497
|
+
|
|
498
|
+
Examples
|
|
499
|
+
--------
|
|
500
|
+
>>> q1 = Quaternion(1, 0, 0, 0)
|
|
501
|
+
>>> q2 = Quaternion(0, 1, 0, 0)
|
|
502
|
+
>>> t = 0.5
|
|
503
|
+
>>> interpolated_quaternion = Quaternion.slerp(q1, q2, t)
|
|
504
|
+
|
|
505
|
+
"""
|
|
506
|
+
epsilon = float_info.epsilon
|
|
507
|
+
|
|
508
|
+
q1 = self.unitized()
|
|
509
|
+
q2 = other.unitized()
|
|
510
|
+
|
|
511
|
+
cosom = q1.dot(q2)
|
|
512
|
+
|
|
513
|
+
interpolated = Rotation()
|
|
514
|
+
quat = list(interpolated.quaternion)
|
|
515
|
+
|
|
516
|
+
# rotate around the shortest angle
|
|
517
|
+
if cosom < 0.0:
|
|
518
|
+
cosom = -cosom
|
|
519
|
+
quat[0] = -q1[0]
|
|
520
|
+
quat[1] = -q1[1]
|
|
521
|
+
quat[2] = -q1[2]
|
|
522
|
+
quat[3] = -q1[3]
|
|
523
|
+
|
|
524
|
+
else:
|
|
525
|
+
quat[0] = q1[0]
|
|
526
|
+
quat[1] = q1[1]
|
|
527
|
+
quat[2] = q1[2]
|
|
528
|
+
quat[3] = q1[3]
|
|
529
|
+
|
|
530
|
+
if (1.0 - cosom) > epsilon:
|
|
531
|
+
omega = math.acos(cosom)
|
|
532
|
+
sinom = math.sin(omega)
|
|
533
|
+
sc1 = math.sin((1.0 - t) * omega) / sinom
|
|
534
|
+
sc2 = math.sin(t * omega) / sinom
|
|
535
|
+
else:
|
|
536
|
+
sc1 = 1.0 - t
|
|
537
|
+
sc2 = t
|
|
538
|
+
|
|
539
|
+
qw_interp = sc1 * quat[0] + sc2 * q2[0]
|
|
540
|
+
qx_interp = sc1 * quat[1] + sc2 * q2[1]
|
|
541
|
+
qy_interp = sc1 * quat[2] + sc2 * q2[2]
|
|
542
|
+
qz_interp = sc1 * quat[3] + sc2 * q2[3]
|
|
543
|
+
|
|
544
|
+
return Quaternion(qw_interp, qx_interp, qy_interp, qz_interp)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This library for transformations partly derived and was re-implemented from the
|
|
3
|
+
following online resources:
|
|
4
|
+
|
|
5
|
+
* http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
|
|
6
|
+
* http://www.euclideanspace.com/maths/geometry/rotations/
|
|
7
|
+
* http://code.activestate.com/recipes/578108-determinant-of-matrix-of-any-order/
|
|
8
|
+
* http://blog.acipo.com/matrix-inversion-in-javascript/
|
|
9
|
+
|
|
10
|
+
Many thanks to Christoph Gohlke, Martin John Baker, Sachin Joglekar and Andrew
|
|
11
|
+
Ippoliti for providing code and documentation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from compas.geometry import Transformation
|
|
15
|
+
from compas.geometry import cross_vectors
|
|
16
|
+
from compas.geometry import decompose_matrix
|
|
17
|
+
from compas.geometry import dot_vectors
|
|
18
|
+
from compas.geometry import identity_matrix
|
|
19
|
+
from compas.geometry import matrix_from_perspective_entries
|
|
20
|
+
from compas.geometry import normalize_vector
|
|
21
|
+
from compas.itertools import flatten
|
|
22
|
+
from compas.tolerance import TOL
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Reflection(Transformation):
|
|
26
|
+
"""Class representing a reflection transformation.
|
|
27
|
+
|
|
28
|
+
A reflection transformation mirrors points at a plane.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
matrix : list[list[float]], optional
|
|
33
|
+
A 4x4 matrix (or similar) representing a reflection.
|
|
34
|
+
check : bool, optional
|
|
35
|
+
If ``True``, the provided matrix will be checked for validity.
|
|
36
|
+
name : str, optional
|
|
37
|
+
The name of the transformation.
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------
|
|
41
|
+
>>> point = [1, 1, 1]
|
|
42
|
+
>>> normal = [0, 0, 1]
|
|
43
|
+
>>> R1 = Reflection.from_plane((point, normal))
|
|
44
|
+
>>> R2 = Transformation([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 2], [0, 0, 0, 1]])
|
|
45
|
+
>>> R1 == R2
|
|
46
|
+
True
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, matrix=None, check=False, name=None):
|
|
51
|
+
if matrix and check:
|
|
52
|
+
_, _, _, _, perspective = decompose_matrix(matrix)
|
|
53
|
+
if not TOL.is_allclose(flatten(matrix), flatten(matrix_from_perspective_entries(perspective))):
|
|
54
|
+
raise ValueError("This is not a proper reflection matrix.")
|
|
55
|
+
super(Reflection, self).__init__(matrix=matrix, name=name)
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_plane(cls, plane):
|
|
59
|
+
"""Construct a reflection transformation that mirrors wrt the given plane.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
plane : [point, vector] | :class:`compas.geometry.Plane`
|
|
64
|
+
The reflection plane.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
:class:`compas.geometry.Reflection`
|
|
69
|
+
The reflection transformation.
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
point, normal = plane
|
|
73
|
+
normal = normalize_vector((list(normal)))
|
|
74
|
+
matrix = identity_matrix(4)
|
|
75
|
+
for i in range(3):
|
|
76
|
+
for j in range(3):
|
|
77
|
+
matrix[i][j] -= 2.0 * normal[i] * normal[j]
|
|
78
|
+
for i in range(3):
|
|
79
|
+
matrix[i][3] = 2 * dot_vectors(point, normal) * normal[i]
|
|
80
|
+
return cls(matrix)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_frame(cls, frame):
|
|
84
|
+
"""Construct a reflection transformation that mirrors wrt the given frame.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
frame : [point, vector, vector] | :class:`compas.geometry.Frame`
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
:class:`compas.geometry.Reflection`
|
|
93
|
+
The reflection transformation.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
if isinstance(frame, (tuple, list)):
|
|
97
|
+
point = frame[0]
|
|
98
|
+
zaxis = cross_vectors(frame[1], frame[2])
|
|
99
|
+
else:
|
|
100
|
+
point = frame.point
|
|
101
|
+
zaxis = frame.zaxis
|
|
102
|
+
return cls.from_plane((point, zaxis))
|