Translation#

class named_arrays.transformations.Translation(vector)#

Bases: AbstractTranslation, Generic[VectorT]

A translation-only vector transformation.

Examples

Translate a vector using a single transformation

import matplotlib.pyplot as plt
import astropy.units as u
import astropy.visualization
import named_arrays as na

vector = na.Cartesian2dVectorArray(
    x=12 * u.mm,
    y=12 * u.mm,
)

transformation = na.transformations.Translation(vector)

square = na.Cartesian2dVectorArray(
    x=na.ScalarArray([-10, 10, 10, -10, -10] * u.mm, axes="vertex"),
    y=na.ScalarArray([-10, -10, 10, 10, -10] * u.mm, axes="vertex"),
)

square_transformed = transformation(square)

with astropy.visualization.quantity_support():
    plt.figure();
    plt.gca().set_aspect("equal");
    na.plt.plot(square, label="original");
    na.plt.plot(square_transformed, label="translated");
    plt.legend();
../_images/named_arrays.transformations.Translation_0_0.png

Translate a vector using an array of transformations

vector_2 = na.Cartesian2dVectorArray(
    x=na.ScalarArray([12, -12] * u.mm, axes="transform"),
    y=9 * u.mm,
)

transformation_2 = na.transformations.Translation(vector_2)

square_transformed_2 = transformation_2(square)

with astropy.visualization.quantity_support():
    plt.figure();
    plt.gca().set_aspect("equal");
    na.plt.plot(square, label="original");
    na.plt.plot(square_transformed_2, axis="vertex", label="translated");
    plt.legend();
../_images/named_arrays.transformations.Translation_1_0.png

Attributes

inverse

A new transformation that reverses the effect of this transformation.

shape

The shape of the transformation.

vector

A vector representing the translation.

Methods

__init__(vector)

Inheritance Diagram

Inheritance diagram of named_arrays.transformations.Translation
Parameters:

vector (VectorT)

property inverse: Self#

A new transformation that reverses the effect of this transformation.

property shape: dict[str, int]#

The shape of the transformation.

vector: VectorT = <dataclasses._MISSING_TYPE object>#

A vector representing the translation.