jgerstmayr / EXUDYN

Multibody Dynamics Simulation: Rigid and flexible multibody systems
https://www.youtube.com/channel/UCsQD2bIPBXB_4J23WtqKkVw/playlists
Other
166 stars 23 forks source link

ValueError when using graphics.FromSTLfile #73

Closed ManuelZ closed 2 months ago

ManuelZ commented 3 months ago
Traceback (most recent call last):
    ...
    graphics.FromSTLfile(
  File "C:\...\Lib\site-packages\exudyn\graphics.py", line 1426, in FromSTLfile
    if A == []: A=np.eye(3)
       ^^^^^^^
ValueError: operands could not be broadcast together with shapes (3,3) (0,)

This happens when calling FromSTLfile with Aoff=RotationMatrixX(theta), because the RotationMatrix functions return a Numpy array and the == operation is making Numpy compare the shapes of Aoff and [], but the broadcasting rules' conditions are not met, hence the ValueError.

Link

Could a potential solution be to replace A == [] and p == [] with len(A) == 0 and len(p) == 0? That worked for me.

Exudyn 1.8.52.dev1.

jgerstmayr commented 2 months ago

You are right! will be changed in version 1.8.55 to:

    if not IsEmptyList(p) or not IsEmptyList(A):
        if IsEmptyList(p): p=[0,0,0]
        if IsEmptyList(A): A=np.eye(3)
        HT = HomogeneousTransformation(A, p)

        data.transform(HT)

with the new function:

def IsEmptyList(x):
    if isinstance(x, list) or isinstance(x, np.ndarray):
        return len(x) == 0
    return False 

you can change your file locally in between or convert numpy arrays to lists of lists! I will also check other places as this pops up now and then.