-
Notifications
You must be signed in to change notification settings - Fork 5
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
Additional property setters #125
Comments
|
@vyasr The purpose of a “rescale” method is to account for everything except the dimensionality. In my definition, scalar multiplication on a circle would apply linearly to radius and circumference but quadratically to area. Each class would define a “linear rescaling.” For some classes like spheropolyhedra, the scaling is more than 1 line of code, so being able to scale with one line is helpful and prevents re-implementation for all the different setters (more than three times in each class 😉). The scale factor used is the square root of a ratio of areas or the cube root of a ratio of volumes. Does that clarify what I mean / why it would be useful? |
I think I'm just confused because defining some abstract concept of rescaling for all classes seems overengineered, especially since it would be an internal detail anyway. For instance, in your original proposal you suggested implementing area setters as taking the square root of area ratios, then calling rescale. My interpretation is then that rescale accepts a single parameter Ellipsoids (2D and 3D) are somewhere in the middle, but I think the implementation of those would probably be simplified if the internals replaced separate Long story short: I'm a fan of trying to avoid duplication, but in this case I think it makes more sense to determine on a case-by-case basis where it would help and where it would introduce more noise. |
I think this issue has been resolved to the extent that it needs to be. The only thing that's not resolved is setting the vertices of polytopes, which can be implemented if someone has a use-case later. |
Overview
The package currently has setters for many shape attributes, allowing users to "normalize" or otherwise rescale various shapes. For example,
Sphere.volume
can be set to a value, and the radius will be changed accordingly.New setters
Some shapes are missing setters, like
Ellipse.perimeter
orEllipsoid.surface_area
. A thorough search should be done to add setters for all getters. The style should match that of #124.Rescaling
I recommend the addition of a
_rescale
function (with an abstract method at theShape
level) that is defined for each shape class. Then, for instance, area setters can be implemented inShape2D
(with an abstract getter) simply by computing a ratio of current area to new area, taking the square root, and calling the shape's_rescale
function. This is also a straightforward path to enable scalar multiplication #41.Notes on accuracy and stability
For some shapes, e.g. circles and spheres, the radius for a given area/volume can be computed analytically. For other shapes, e.g. ellipses, the perimeter (or ellipsoid surface area) relies on elliptical integrals, which might not be accurate to full double precision (I don't know but I recall having slight issues with the precision in testing).
For the analytical cases, it may be preferable to use the analytical formula instead of rescaling the radius based on a ratio of current/new area, etc. For the cases that rely on elliptical integrals, we can probably count on it being "good enough precision."
The text was updated successfully, but these errors were encountered: