Reputation: 541
I'm developing some lecture notes on numerical methods in an ipython notebook, and I need to include some coordinate transformation functions. I've already coded these functions (below), but the details aren't exactly fundamental to the topic, and it would simplify the lecture if I could call pre-written functions.
I see the scipy image rotation function, but I just need coordinate translation and rotation. ie
# transform from global to panel coordinates
def transformXY( self, x, y ):
xp = x-self.xc
yp = y-self.yc
xpp = xp*self.sx+yp*self.sy
ypp = yp*self.sx-xp*self.sy
return [ xpp, ypp ]
# rotate velocity back to global coordinates
def rotateUV( self, u, v):
up = u*self.sx-v*self.sy
vp = v*self.sx+u*self.sy
return [ up, vp ]
In these, sx
and sy
are the unit tangent vector components.
Upvotes: 1
Views: 3996
Reputation: 5855
Copied and expanded from previous comment:
You can also move your own functions into a separate .py file and import them from there. That way their internals are hidden in the notebook.
If you place them in a file/module called e.g. transformation.py
and place that file next to your notebook file , you can then import your functions with from transformation import *
As has been suggested in a now deleted answer, I would recommend using matrices for any transformation, especially rotations. This is in my opinion much clearer than element-wise modifications.
EDIT: Afaik there are no predefined coordinate-transformation functions in numpy. In sympy there is something, but I'm not sure how useful it is, it seams a bit much for a simple transformation. For transformations via matrices google found me the this module, which appears to be quite comprehensive.
Upvotes: 1