Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scalar multiplication for shapes #41

Open
bdice opened this issue Jan 19, 2020 · 6 comments
Open

Scalar multiplication for shapes #41

bdice opened this issue Jan 19, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@bdice
Copy link
Member

bdice commented Jan 19, 2020

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 bdice added the enhancement New feature or request label Jan 19, 2020
@bdice
Copy link
Member Author

bdice commented Jan 19, 2020

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 bdice changed the title Scalar multiplication for polygons/polyhedra Scalar multiplication for shapes Jan 19, 2020
@vyasr
Copy link
Contributor

vyasr commented Jan 19, 2020

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.

@vasudevanv
Copy link

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

@bdice
Copy link
Member Author

bdice commented Apr 16, 2022

@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
Copy link
Member Author

bdice commented Apr 16, 2022

@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

@vasudevanv
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants