Visualizing matrix transformations in 2- and 3-space

18 views
Skip to first unread message

d❤vid seaward

unread,
Apr 28, 2011, 3:25:49 AM4/28/11
to scitools
Hi all,

I want to visualize matrix transformations in 2- and 3-space. I've
tried finding an existing tool to do this to no avail, but stumbled on
scitools/easyviz as an option to do it (almost) myself.

I'd like to be able to enter a vector or matrix, see it in 2-space or
3-space, enter a transformation vector or matrix, and see the result.
For example, enter a 3x3 matrix, see the parallelepiped it represents,
enter a rotation matrix, see the rotated parallelepiped.

I'm a bit overwhelmed by the number of components in scitools. Which
components would I be using for 2D matrix visualization, and which for
3D?

Thanks!

David

Johannes Ring

unread,
Apr 28, 2011, 4:57:42 AM4/28/11
to scit...@googlegroups.com
Hi David,

Have you had a look at the Easyviz documentation? It's available from here:

http://code.google.com/p/scitools/wiki/EasyvizDocumentation

Johannes

> --
> You received this message because you are subscribed to the Google Groups "scitools" group.
> To post to this group, send email to scit...@googlegroups.com.
> To unsubscribe from this group, send email to scitools+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/scitools?hl=en.
>
>

d❤vid seaward

unread,
Apr 28, 2011, 9:20:57 AM4/28/11
to scitools
On Apr 28, 10:57 am, Johannes Ring <joha...@simula.no> wrote:
> Have you had a look at the Easyviz documentation? It's available from here:

Hi Johannes,

Yes, thanks :) I can see instructions on plotting 2D curves and
quivers, but I just want straight lines, unless I'm misunderstanding
quivers and you can plot just one or two at a time? For 3D stuff I can
see instructions on surfaces, but again I want just wireframe lines in
3-space.

It has been a long time since I fiddled with Matlab, but if someone
can show me how to define and plot a transformable 2x2 matrix in 2-
space and a 3x3 in 3-space I think I can take it from there.

David

Hans Petter Langtangen

unread,
Apr 28, 2011, 4:20:23 PM4/28/11
to scit...@googlegroups.com
Hi, I dont't understand what your are trying to plot. Can you define it
precisely in mathematical terms? To me, plotting a "transformable 2x2
matrix in 2-space" does not map to any type of plot I've heard about...

Hans Petter

d❤vid seaward

unread,
Apr 29, 2011, 1:34:17 AM4/29/11
to scitools
On Apr 28, 10:20 pm, Hans Petter Langtangen <h...@simula.no> wrote:
> Hi, I dont't understand what your are trying to plot. Can you define it
> precisely in mathematical terms? To me, plotting a "transformable 2x2
> matrix in 2-space" does not map to any type of plot I've heard about...

Hello Hans,

I think the confusion might be in the word "transformable". By this I
just meant a Python object that I could perform matrix math with, for
example multiplying it by another matrix to achieve a rotation.

So, I want to take an arbitrary 2x2 matrix, plot its core vectors onto
a Cartesian plane, multiply the original matrix by another (let's say
a shear or a rotation) and plot the core vectors of the result onto
the plane in a different colour.

I imagine it looking something like this:

def plot_2x2_matrix(matrix):
point_0 = [0,0] # origin
point_1 = (matrix[0][0] , matrix[0][1]) # column 1
point_2 = (matrix[1][0] , matrix[1][1]) # column 2
point_3 = (matrix[0][0] + matrix[1][0] , matrix[0][1] + matrix[1]
[1])
# point_3 is the sum of column 1 & 2

axis.plot(point_0, point_1) # vector 1
axis.plot(point_0, point_2) # vector 2
axis.plot(point_0, point_3) # combined vector
axis.plot(point_1, point_3)
axis.plot(point_2, point_3)
# last two finish off the "box"

def 2x2_transformation(matrix, transformation):
result = matrix * transformation
plot_2x2_matrix(matrix)
plot_2x2_matrix(result)

def main():
matrix_a = [[1,3] , [2,4]] # an arbitrary matrix
rotate_90 = [[0, 1] , [-1, 0]] # transformation
# I presume there's a good (NumPy) type for storing matrices
2x2_transformation(matrix_a, rotate_90)

What I'm looking for are which objects and methods I need to do this.
And then I want to do it all over again for a 3x3 matrix on a 3
dimensional axis.

Hope this has clarified things. Thanks for the feedback and any
guidance you can provide!

David

Johannes Ring

unread,
Apr 29, 2011, 3:29:37 AM4/29/11
to scit...@googlegroups.com
Hi David,

The attached script is a slight modification of your code to make it
run with easyviz. Have a look and see if the result matches what you
want.

> And then I want to do it all over again for a 3x3 matrix on a 3
> dimensional axis.

This would require the use of the plot3 command instead of plot. The
plot3 command is currently only supported by the vtk backend.

Johannes

Johannes Ring

unread,
Apr 29, 2011, 3:31:12 AM4/29/11
to scit...@googlegroups.com
Sorry, forgot to attach the script.

Johannes

test.py

d❤vid seaward

unread,
Apr 29, 2011, 5:23:10 AM4/29/11
to scitools
Thanks Johannes, that's exactly what I needed, I'll try it out! I'll
also give the vtk backend a bash and post any queries/problems/
successes.

David

Hans Petter Langtangen

unread,
Apr 29, 2011, 12:38:07 PM4/29/11
to scit...@googlegroups.com
I just happened to need something similar myself for teaching, but I need to display vectors with arrows, not just lines (maybe that is what you also want?). The idea is to use quiver, but that function plots a vector field, while I want only one vector, at the origin, to be displayed. This can be achieved by letting all vectors in the field on the grid be (0,0), except the one at the origin. I can use just 1x1 cell grid. See the attached file.
This example is now in scitools/examples in the hg version at googlecode.

Best regards,
Hans Petter

rotate_vector.py
Reply all
Reply to author
Forward
0 new messages