A small utility program in Python (pygame + numpy) to visualize concepts of linear transformations executed in browser using pyodide. Watch 3Blue1Brown for a nice introduction.
np.linalg.inv(T1)
to calculate the inverse of a transform. You can move around in the plane with the mouse. Zoom is controlled with the mouse wheel. If you click on the button on the left top, a menu opens.
The menu shows three sections:
To select an object click on the created transform and then on the left side on one of the objects. Then click on the transformed again and click on the transformation you want to use.
This only works for 2-dimensional transformation matrices (WIP).
The last add button creates a custom-transformation. If you click on the custom transformation a window will pop up, that enables you to write python code.
See [Custom Transformed](#custom-transformed) for more information. To close the window press `Esc`. You can remove the last sign with `Backspace` and everything with `Del`.
As you can see, this editor is very rudimentary (no removal/edit of signs that are not the last sign).
Del
or Backspace
.LINE
and POINT
by hovering over a rendered element on the left side and pressing r
.v
.If you create a custom transformed and click on it, a text window appears. Here you can write a python expression.
You can use all object names listed above and numpy functions (accessible via np
). Objects from above will be presented as numpy-ndarray.
Example: Lets say you have a vector v1
and a 2d transformation matrix T1
. You could write T1 @ v1
to apply the transformation matrix on your vector and render the result.
The same works for unit circles (replace v1
with u1
).
As applying a 3d transformation matrix on a 2d vector is a bit complicated, you can use the special function mm()
(matrix-multiplication): mm(T1, v1)
.
# clone repository
git clone https://github.com/Bluemi/linear-algebra-testcase.git
cd linear-algebra-testcase
# install requirements (numpy, pygame)
pip3 install -r requirements.txt
# run the programm
python3 ./src/main.py
Consider using a virtual python-environment (eg virtualenvwrapper).
eval()
is used, which allows arbitrary code execution. For example, you could use exit()
as formula to end the program. So be a bit careful.