# rotate object given center and degrees

Hi,

I have several VTK files that are exported from a processing software. To save memory for the 3d grid, the coordiantes are rotated, given a xy center and a degree. Those values are known.

Since I have several of those files, I want to actual plot them with the actual coordinates they belong. Is it possible to rotate the coordiantes of the object (rotation along the z-axis) if I provide the xy center and the angle?
Right now, I am doing this by ediitng the VTK files, but perhaps there is a better way to do so.

Best

The Transform filter can do this. You might need to chain a couple together for proper rotation, though. First, apply a Transform filter with Translate properties set to (-x, -y , 0). In a second Transform filter, you can set the Rotate setting to (0, 0, degrees), then in a third Transform filter, set the Translate setting to (x, y, 0).

This won’t be the fastest way and will create a copy of the points for as many Transform filters as you have., but it is straightforward. You could instead use the Python Calculator with a one-line Python expression that applies these transforms once you work out the transformation math. That would be more memory efficient as it would make just one copy of the transformed points. Numpy is available in the Python Calculator by the way in case that helps.

1 Like

Cory’s solution works if you want to rotate all the points in your mesh by the same angle, but from the description, it sounds like you have a different rotation for each point (so that you can condense the x,y pair with a single rotation value). You can convert the rotation (and height along z) to an x,y,z position using the `Calculator` filter. When you create the `Calculator`, also turn on the `Coordinate Results` so that the position of each point gets set to the result. The expression will look something like this.

``````(cos(degrees * 3.14159/180) + x_center)*iHat + (sin(degrees * 3.14159/180) + y_center)*jHat + height*kHat
``````

In the expression above, replace `degrees` with the field that specifies the rotation for each point in the 3D mesh. Replace `x_center` and `y_center` with the x,y center you said you have. Replace `height` with the z position of each point. (You didn’t say you had a z position, but you said it is a 3D mesh, so you must have it.)

As Cory suggested, you should also be able to do this with the `Python Calculator` and it would probably be faster, but I find the regular `Calculator` easier to use.

Thanks both. I have to think how to do this, I am doing something wrong and it’s not working now.

Just to clarify a bit, I have several vtk files (each file is an unstructured grid). Each vtk has to be rotated individual from the other one, but all coordinate within each file must rotated and shifted by the same numbers.

P.S.
I am a bit puzzled by the height input, on how to do this now. Anyhow, I will try to figure it out.