manim icon indicating copy to clipboard operation
manim copied to clipboard

v0.18.1 weird behavior of Axes().coords_to_point / Axes().c2p

Open uwezi opened this issue 11 months ago • 2 comments

Description of bug / unexpected behavior

According to the documentation, the argument of .c2p() may be individual values for x, y (and z), as well as lists, lists of lists and numpy.arrays. However, when using just lists [x,y,z] or 1D np.arrays the returned coordinates are wrong.

Expected behavior

How to reproduce the issue

Code for reproducing the problem

class testc2p(Scene):
    def construct(self):
        ax = Axes()
        print("ax.c2p(1,2) = ",ax.c2p(1,2))
        print("ax.c2p(1,2,1) = ",ax.c2p(1,2,1))
        print("ax.c2p(np.array([1,2])) = ",ax.c2p(np.array([1,2])))
        print("ax.c2p(np.array([1,2,1])) = ",ax.c2p(np.array([1,2,1])))
        print("ax.c2p([1,2,1]) = ",ax.c2p([1,2,1]))
        print("ax.c2p([1,2]) = ",ax.c2p([1,2]))
        print("ax.c2p([[1,2],[2,3]]) = ",ax.c2p([[1,2],[2,3]]))

returns

Manim Community v0.18.1

ax.c2p(1,2)   =  [0.85714286 1.5        0.        ]
ax.c2p(1,2,1) =  [0.85714286 1.5        0.        ]
ax.c2p(np.array([1,2])) =  [[0.85714286 1.71428571]
                            [0.         0.        ]
                            [0.         0.        ]]
ax.c2p(np.array([1,2,1])) =  [[0.85714286 1.71428571 0.85714286]
                              [0.         0.         0.        ]
                              [0.         0.         0.        ]]
ax.c2p([1,2,1]) =  [[0.85714286 1.71428571 0.85714286]
                    [0.         0.         0.        ]
                    [0.         0.         0.        ]]
ax.c2p([1,2]) =  [[0.85714286 1.71428571]
                  [0.         0.        ]
                  [0.         0.        ]]
ax.c2p([[1,2],[2,3]]) =  [[0.85714286 1.5        0.        ]
                          [1.71428571 2.25       0.        ]]
  • ax.c2p(1,2) and ax.c2p(1,2,1) return reasonable values
  • ax.c2p(np.array([1,2])) appears to be treated as two "points" with x=1 and x=2 respectively, returning [[x1, x2],[y1, y2],[z1, z2]] rather than [[x1 y1 z1],[x2, y2, z2]], similar for all other 1D-lists
  • ax.c2p([[1,2],[2,3]]) appears to correctly return two points

System specifications

System Details
  • OS : Windows 10
  • RAM: enough
  • Python version (python/py/python3 --version): 3.11.6

uwezi avatar Dec 27 '24 09:12 uwezi

Let me preface this by saying that I'm (personally) not a big fan of this behavior.

However, the reason for this is when passing a list (ax.c2p([1,2])) it's treating it as you passed a list of the structure [x1, x2], [y1, y2], [z1, z2] - see the implementation if you're interested. (edit: oops you already figured this out)

I would like to make this behavior less confusing, so I'm open to ideas!

JasonGrace2282 avatar Dec 30 '24 15:12 JasonGrace2282

I would say the expected behavior would be: list of coordinates - in list of coordinates out But I can also imagine that it is not easy to distinguish the different formats. But I think the following behavior would be more logical axes.c2p(x,y,z) -> np.array([X, Y, Z]) axes.c2p([[x,y,z]]) -> [np.array([X, Y, Z])] axes.c2p([[x1,y1,z1],[x2,y2,z2]]) -> [np.array([X1, Y1, Z1]),np.array([X2, Y2, Z2])] Personally I cannot see any use case where I would expect to get individual lists of the Xs, Ys and Zs back...

uwezi avatar Dec 30 '24 15:12 uwezi