1

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.

weymouth
  • 521
  • 6
  • 17

1 Answers1

1

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.

PeterE
  • 5,715
  • 5
  • 29
  • 51
  • 3
    Using `import *` is usually a [bad idea](http://stackoverflow.com/a/2386740/1461210) – ali_m Mar 28 '15 at 18:50
  • @ali_m True enough. My point was more about the fact that the folder the notebook is in is searched for modules to import. – PeterE Mar 28 '15 at 20:50
  • Yes, that would work for me, I guess. For posterity - is the answer to my question, "no". – weymouth Mar 29 '15 at 01:41
  • 1
    You *can* also apply translations (basically *all* [affine transformations](http://en.wikipedia.org/wiki/Affine_transformation)) with matrices, if you use [homogeneous coordinates](http://en.wikipedia.org/wiki/Homogeneous_coordinates). – Roland Smith Mar 29 '15 at 15:37