Visualizing Linear Transformations with Sage

423 Views Asked by At

Perhaps this isn't the best place to ask this, but there is no Sage specific stackexchange, so here I am.

I would like to be able to produce the geometric effect of a linear transformation, either on the plane or $\mathbb{R}^3$ (preferably both), to aid in a final paper and presentation this semester. Most of the widgets I've found online are lacking. I'd like to have more personalization options than you can find in https://www.geogebra.org/m/ssO8VOrw or https://shadanan.github.io/MatVis/.

I'd like to be able to implement the code for transforming the cat face in Mathematica, found here https://mathematica.stackexchange.com/questions/46392/visualization-of-matrix-transformations, in Sage (or CoCalc, whichever). I've never used Mathematica and don't have access to it on my personal machine, and implementing this in Sage seems outside of my current abilities. Any help would be greatly appreciated.

1

There are 1 best solutions below

1
On

You can definitely do this. Here is a 2D example, not original to me.

var('t')
@interact
def _(A=matrix(RDF,[[1,0],[0,1]]),auto_update=False):
    pll=A*vector((-0.5,0.5))
    plr=A*vector((-0.3,0.5))
    prl=A*vector((0.3,0.5))
    prr=A*vector((0.5,0.5))
    left_eye=line([pll,plr])+point(pll,size=5)+point(plr,size=5)
    right_eye=line([prl,prr],color='green')+point(prl,size=5,color='green')+point(prr,size=5,color='green')
    mouth=parametric_plot(A*vector([t, -0.15*sin(2*pi*t)-0.5]), (t, -0.5,
0),color='red')+parametric_plot(A*vector([t, -0.15*sin(2*pi*t)-0.5]), (t,0,0.5),color='orange')
    face=parametric_plot(A*vector([cos(t),sin(t)]),
(t,0,pi/2),color='black')+parametric_plot(A*vector([cos(t),sin(t)]),
(t,pi/2,pi),color='lavender')+parametric_plot(A*vector([cos(t),sin(t)]),
(t,pi,3*pi/2),color='cyan')+parametric_plot(A*vector([cos(t),sin(t)]),(t,3*pi/2,2*pi),color='sienna')
    P=right_eye+left_eye+face+mouth
    html('smiley guy transformed by $A$')
    P.show(aspect_ratio=1,figsize=4)