LinearTransformation#

class named_arrays.transformations.LinearTransformation(matrix)#

Bases: AbstractLinearTransformation, Generic[MatrixT]

A vector transformation represented by a matrix multiplication.

Examples

Rotate a vector using a linear transformation

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

angle = 53 * u.deg
matrix = na.Cartesian2dRotationMatrixArray(angle)

transformation = na.transformations.LinearTransformation(matrix)

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="rotated");
    plt.legend();
../_images/named_arrays.transformations.LinearTransformation_0_0.png

Rotate a vector using an array of transformations

angle_2 = na.ScalarArray([30, 45] * u.deg, axes="transform")
matrix_2 = na.Cartesian2dRotationMatrixArray(angle_2)

transformation_2 = na.transformations.LinearTransformation(matrix_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="rotated");
    plt.legend();
../_images/named_arrays.transformations.LinearTransformation_1_0.png

Attributes

inverse

A new transformation that reverses the effect of this transformation.

matrix

shape

The shape of the transformation.

Methods

__init__(matrix)

Inheritance Diagram

Inheritance diagram of named_arrays.transformations.LinearTransformation
Parameters:

matrix (MatrixT)

property inverse: Self#

A new transformation that reverses the effect of this transformation.

matrix: MatrixT = <dataclasses._MISSING_TYPE object>#
property shape: dict[str, int]#

The shape of the transformation.