2d Affine Matrix with Point transformations

Monkey Forums/Monkey Code/2d Affine Matrix with Point transformations

NoOdle(Posted 2011) [#1]
I have been a lazy programmer over the years... spent a few days learning matrices which I should have done when I first started, my god they are useful!

Below are some classes to handle rectangles, points and 2d Affine Matrices. Also some very handy methods for doing stuff with them.

The below example shows how to manipulate a shape using the matrix and draw it. It also shows how to test if you have clicked on the transformed shape by inverting the matrix and transforming the mouse. The transformed co-ords are then checked against the original un transformed rect for simple point in rect.


Arrow Keys, WASD, z/x, 1/2/3/4 to adjust the matrix. Use mouse to click on the transformed shape and see the result. Change debugOn bool to True to see what it is happening.


Enjoy :)





DruggedBunny(Posted 2011) [#2]

... inverting the matrix and transforming the mouse. The transformed co-ords are then checked against the original un transformed rect for simple point in rect.


Clever stuff! Thanks for sharing it. Nice lookin' code, too.


NoOdle(Posted 2011) [#3]
Clever stuff! Thanks for sharing it. Nice lookin' code, too.


Thank you!


Gerry Quinn(Posted 2012) [#4]
Really useful! I want to try shearing images and without this it would have been pretty much trial and error...


dragon(Posted 2012) [#5]
good timing... i needed inverse matrix function


Why0Why(Posted 2012) [#6]
Noodle, I have posted on some of your other code but it is awesome that you share so much. Your code is usually elegant and useful. So thanks again, if you are ever in the neighborhood, drinks are on me!


Amon(Posted 2012) [#7]
NoOdle is the new Brucy! :)