coxeter
coxeter copied to clipboard
Scalar multiplication for shapes
Feature description
I would like to be able to multiply a polyhedron or polygon by a scaling factor, which would apply as a scalar multiplication to its vertex vectors. Similarly, radii of spheres or spheropolytopes would scale linearly.
Proposed solution
Implement __mul__
, etc: https://docs.python.org/3/library/operator.html#operator.mul
The operations should return a new shape instance.
Candidates:
-
__mul__
forshape * 1.5
-
__matmul__
forshape @ three_by_three_transformation_matrix
-
__truediv__
forshape / 1.5
Other things like negation (multiply all vertex vectors by -1), vector addition to all vertices, etc. are possible if desired.
Related: the volume
property could be settable, which would trigger a rescaling of vertices.
Sketch (not tested):
@volume.setter
def volume(self, value):
self.vertices *= (value / self.volume)**(1/3)
The volume is already settable. The other operators are good ideas, we should probably first have a broader discussion implementing operators for shapes before jumping in and implementing them to make sure that we're covering use-cases. This discussion would impact #23.
Are there any plans to support shape orientation and rotation operations in the future?
@vasudevanv You might be interested in the rowan package: https://rowan.readthedocs.io/en/latest/
The rowan library has a variety of routines for dealing with quaternions, including 3D rotations and point-cloud registration.
If you want more information or an example, let us know what you need and we can help!
@vasudevanv A simple example of rotating the vertices of a ConvexPolyhedron can be found here: https://coxeter.readthedocs.io/en/latest/examples/InertiaTensors.html?highlight=rowan
@bdice Thank you so much. That was exactly what I was looking for.