tjstienstra/symmeplot

add_body does not accept scale kwarg

Closed this issue · 6 comments

The scale= kwarg seems to set the length of the unit vectors attached to a reference frame. I tried doing Scene.add_frame(frame, scale=1.5) but got an error message (I forgot what exactly). First, a question, is the function of the scale kwarg to only set the length of the triad of unit vectors? If it is, should add_frame() accept it?

Yes, the scale kwarg is the length of the unit vectors of the reference frame. The following works fine for me.

import numpy as np
from symmeplot.matplotlib import Scene3D
from sympy.physics.mechanics import Point, ReferenceFrame, dynamicsymbols

# Create the system in sympy
N = ReferenceFrame("N")
A = ReferenceFrame("A")
q = dynamicsymbols("q")
A.orient_axis(N, N.z, q)
N0 = Point("N_0")
v = 0.2 * N.x + 0.2 * N.y + 0.7 * N.z
A0 = N0.locatenew("A_0", v)
# Create the instance of the scene specifying the inertial frame and origin
scene = Scene3D(N, N0, scale=0.5)
# Add the objects to the system
scene.add_vector(v)
scene.add_frame(A, A0, ls="--", scale=0.3)
scene.add_point(A0, color="g")
# Evaluate the system.
scene.lambdify_system(q)
scene.evaluate_system(0.5)
# Plot the system
scene.plot()

Sorry, I misremembered this. The error is with add_body() which also seems to attach a triad of unit vectors to the reference frame associated with the body.

Traceback (most recent call last):
  File "/home/moorepants/src/bicycle-kickplate-model/mplviz.py", line 40, in <module>
    rear_wheel_plot = scene.add_body(rear_wheel, scale=2.0)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/symmeplot/core/scene.py", line 221, in add_body
    obj = self._PlotBody(self.inertial_frame, self.zero_point, body, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/symmeplot/matplotlib/plot_objects.py", line 395, in __init__
    PlotPoint(inertial_frame, zero_point, masscenter, **properties[0]))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/symmeplot/matplotlib/plot_objects.py", line 73, in __init__
    Line3D([0], [0], [0], **{**self._get_style_properties(style), **kwargs}),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/symmeplot/matplotlib/artists.py", line 40, in __init__
    super().__init__(np.array(x, dtype=np.float64),
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/mpl_toolkits/mplot3d/art3d.py", line 208, in __init__
    super().__init__([], [], *args, **kwargs)
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/matplotlib/lines.py", line 407, in __init__
    self._internal_update(kwargs)
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/matplotlib/artist.py", line 1216, in _internal_update
    return self._update_props(
           ^^^^^^^^^^^^^^^^^^^
  File "/home/moorepants/miniconda/envs/bicycle-kickplate-model/lib/python3.12/site-packages/matplotlib/artist.py", line 1190, in _update_props
    raise AttributeError(
AttributeError: Line3D.set() got an unexpected keyword argument 'scale'

I was trying to figure out how to increase the length of the unit vectors associated with a body.

add_body passes the kwargs to PlotBody. It is mentioned in the [documentation of PlotBody](https://tjstienstra.github.io/symmeplot/api/matplotlib/plot_objects.html#symmeplot.matplotlib.plot_objects.PlotBody) that kwargsin general are applied to both the internalPlotPointandPlotFrame. In case of color="red", this would mean that all vectors and the center of mass becomes red. However, in this case the scaleargument is not supported byPlotPoint. To scale the reference frame you should use scene.add_body(rear_wheel, plot_frame_properties={"scale": 2.0})`.
Maybe I should investigate generating parts of the documentation, such that this becomes easier to find.

There are definitely lots of **kwargs in the docs, but it isn't so easy to trace what it does.

There are definitely lots of **kwargs in the docs, but it isn't so easy to trace what it does.

Yeah, symmeplot highly leverages passing down expecting someone down the line to understand the keyword argument.

Closing in favour of #33.