Source code for ddg.abc

from abc import ABC, abstractmethod

import ddg.math.projective as pmath


[docs]class LinearTransformable(ABC): """Interface for linearly transformable objects. The transformations are projective transformations in homogeneous coordinates. """ ambient_dimension: int
[docs] @abstractmethod def transform(self, F): """Return a linearly transformed copy. The transformation is assumed to be a projective transformation in homogeneous coordinates. Parameters ---------- F : numpy.ndarray of shape (ambient_dimension + 1, ambient_dimension + 1) Returns ------- type(self) """ raise NotImplementedError
[docs] def change_affine_picture(self, before, after=-1): """Transform the object to a different affine view. Dehomogenizing the object post-transform with affine component `after` will produce the same affine picture as dehomogenizing the object pre-transform with affine component `before`. The actual transformation that achieves this just permutes the homogeneous coordinates as follows: It deletes the entry at `before` and inserts it again at position `after`. Here are two examples of how you might use this function: 1. You defined a projective object `X` with a certain affine picture in mind and you followed our convention of using affine component -1. You now want to see what it would look like when dehomogenized using a different affine component `i`. To do this, you would just do ``X_ = X.change_affine_picture(i)`` and then visualize the object normally. 2. You don't like our convention of dehomogenizing by the last component and want to define your object `X` with the affine picture with respect to affine component `i` in mind. To visualize your object as you imagine it, you would also do ``X_ = X.change_affine_picture(i)``. Parameters ---------- before : int after : int (default=-1) Returns ------- type(self) """ return self.transform( pmath.affine_component_transformation( self.ambient_dimension + 1, before=before, after=after ) )