Python conversion between coordinates

前端 未结 7 1726
我寻月下人不归
我寻月下人不归 2020-12-01 05:03

Are there functions for conversion between different coordinate systems?

For example, Matlab has [rho,phi] = cart2pol(x,y) for conversion from cartesian

7条回答
  •  孤独总比滥情好
    2020-12-01 05:39

    Thinking about it in general, I would strongly consider hiding coordinate system behind well-designed abstraction. Quoting Uncle Bob and his book:

    class Point(object)
        def setCartesian(self, x, y)
        def setPolar(self, rho, theta)
        def getX(self)
        def getY(self)
        def getRho(self)
        def setTheta(self)
    

    With interface like that any user of Point class may choose convenient representation, no explicit conversions will be performed. All this ugly sines, cosines etc. will be hidden in one place. Point class. Only place where you should care which representation is used in computer memory.

提交回复
热议问题