# Rotation¶

## Description¶

Rotates the geometry and the vector variables in it.

For two-dimensional bases, a rotation by a given angle is done from the first axis to the second axis in the coordinate system.

For three-dimensional bases, a rotation by a given angle around a given axis direction is performed using the right hand rule.

## Parameters¶

• coordinates: list(str), default= None

The variable names that define the set of coordinates. The coordinate system must be the cartesian coordinate system. If None the internal base coordinate system is used.

• angle: int or float

• axis: list(float), default= None

The axis of rotation (only for three-dimensional bases).

• vectors: list(list(str)), default= []

A list of lists containing name the components of the vectors to be rotated. The components must be specified in the same order as the coordinate keyword.

• memory_mode: bool, default= False

If True, the modifications are done directly on the input base to limit memory usage. If False, a new base is created.

## Preconditions¶

• The base must be in the Cartesian system of coordinates.

• The base must be either two-dimensional or three-dimensional.

• If the base is two-dimensional, the axis keyword must not be specified.

• If the base is three-dimensional, both the angle and axis keywords are needed.

## Postconditions¶

• If memory_mode = False, the input base remains unchanged and the output base has the same structure as the input base. If memory_mode = True, the input base is modified in-place and the returned base is the same object as the input base.

## Example¶

The following example shows how to rotate a base by an angle of 45 degrees around the y axis, rotating also the velocity vector [u, v, w].

```import antares
myt = antares.Treatment('rotation')
myt['base'] = base
myt['coordinates'] = ['x', 'y', 'z']
myt['axis'] = [0, 1, 0]
myt['angle'] = np.pi / 4
myt['vectors'] = [ ['u', 'v', 'w'] ]
rotated_base = myt.execute()
```

## Main functions¶

class antares.treatment.TreatmentRotation.TreatmentRotation
execute()

Rotates the base.

Returns:

the base containing the results.

Return type:

`Base`

## Example¶

The following examples creates a 2D structured base with a scalar and a vector variable and it uses the rotation treatment to rotate the base by 45 degrees.

```import antares
import numpy as np
import os

output_folder = os.path.join("OUTPUT", "TreatmentRotation")
os.makedirs(output_folder, exist_ok=True)

X, Y = np.mgrid[0:10, 0:10]

# Create base to translate
base = antares.Base()
base.init()
base[0][0]['x'] = X
base[0][0]['y'] = Y
base[0][0]['myvar'] = X*Y # create a dummy variable
base[0][0]['myvec_x'] = X+Y # create a vector variable (x component)
base[0][0]['myvec_y'] = np.zeros_like(X) # create a vector variable (y component)

base.coordinate_names = ['x', 'y']

# Dump base to rotate
w = antares.Writer('hdf_antares')
w['base'] = base
w['filename'] = os.path.join(output_folder, 'base_to_rotate')
w.dump()

# Apply rotation treatment
rotation = antares.Treatment('rotation')
rotation['base'] = base
rotation['angle'] = np.pi / 4
rotation['vectors'] = [ ['myvec_x', 'myvec_y'] ]
rotated_base = rotation.execute()

# Dump result
w = antares.Writer('hdf_antares')
w['base'] = rotated_base
w['filename'] = os.path.join(output_folder, 'rotated_base')
w.dump()
```