coxeter icon indicating copy to clipboard operation
coxeter copied to clipboard

Scalar multiplication for shapes

Open bdice opened this issue 5 years ago • 6 comments

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__ for shape * 1.5
  • __matmul__ for shape @ three_by_three_transformation_matrix
  • __truediv__ for shape / 1.5

Other things like negation (multiply all vertex vectors by -1), vector addition to all vertices, etc. are possible if desired.

bdice avatar Jan 19 '20 17:01 bdice

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)

bdice avatar Jan 19 '20 18:01 bdice

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.

vyasr avatar Jan 19 '20 19:01 vyasr

Are there any plans to support shape orientation and rotation operations in the future?

vasudevanv avatar Apr 16 '22 02:04 vasudevanv

@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!

bdice avatar Apr 16 '22 03:04 bdice

@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 avatar Apr 16 '22 03:04 bdice

@bdice Thank you so much. That was exactly what I was looking for.

vasudevanv avatar Apr 16 '22 03:04 vasudevanv