Noob: Understanding transformation.inverse
-
I'm having trouble understanding what transformion.inverse does as I examine other people's code and try to learn.
In TIG's CofGravity.rb code there is a snippet for placing a group...
### add markers at cog etc tgp=entities.add_group(todo) cog_gp=tgp.copy ... ... cog_gp_tr=cog_gp.transformation ... ... ### put into right place ??? cog_gp.transform!(cog_gp_tr.inverse)
I've seen other things like this and people doing it as a matter of course. To me its like the underware gnomes.
- first you get a transformation
- then ???
- then you get its inverse.
For the life of me, I can't figure out what it does. The help says there are lots of examples on the interwebs, - greaaat.
Some help that might make it click in my head would be really appreciated.... like "when you have this, and you want that, then run inverse on it" might do the trick.
Thanks so much!
-
Say that you create a transformation to move an object:
t=Geom::Transformation.new([10,20,30])
(a translation from [0,0,0] to [10,20,30])And you then use that to transform an entity:
group.transform!(t)
Then you have moved that by a certain distance.
If you want to move it back to its original position you can use the inverse transformation.
group.transform!(t.inverse)
-
Thanks, that's a great help.
@thomthom said:
group.transform!(t)
Then you have moved that by a certain distance.
If you want to move it back to its original position you can use the inverse transformation.
group.transform!(t.inverse)
Ok... so suppose you didn't transform it in the first place what would be inferred by [ruby:1tz432dx]group.transform!(t.inverse)
group.transform!(t.inverse)
?Because that is what it looks like its doing in the section above. that might be why TIGs got "### put into right place ???" as a comment. I'd have to ask him of course.
-
If you had not moved it in the first place and you'd move it in the opposite direction.
t=Geom::Transformation.new([10,20,30]) group.transform!(t.inverse)
This would move the group by the vector
-10,-20,-30
If you had a rotation transformation you'd rotate the other way.
If you had a transformation that scaled down then the inverse would scale up.
-
@billwheaton said:
Thanks, that's a great help.
@thomthom said:
group.transform!(t)
Then you have moved that by a certain distance.
If you want to move it back to its original position you can use the inverse transformation.
group.transform!(t.inverse)
Ok... so suppose you didn't transform it in the first place what would be inferred by [ruby:1gvc83k7]group.transform!(t.inverse)
group.transform!(t.inverse)
?Because that is what it looks like its doing in the section above. that might be why TIGs got "### put into right place ???" as a comment. I'd have to ask him of course.
I recently had to learn this, myself. So here is my take on this. Maybe it will make more sense with an anlogy to multiplying numbers instead of matrices. So, a matrix inverse is analoguous to the "Multiplicative Inverse of a Number" or also called "Reciprocal".
http://www.mathwords.com/m/multiplicative_inverse_of_a_number.htmIf there is no transformation than the transformation matrix is the identity matix (analoguous to the number 1)
So using this analogy and assuming the tranformation is say 5, we have this equation for what TIG is doing:
5 * (1/5) = 1But if there was never a transformation to begin with, then the equation would just end up like this:
1 * (1/1) = 1-Kwok
-
The basics of transformation matrices are explained in Appendix T of my tutorial.
The use of transformation matrices is explained in Chapter 15 of my tutorial.
Software that lets you move, rotate and scale component instances is explained in Chapter 16 of my tutorial.
-
Thanks Martin. And I read those and they were a great help, but I didn't find much there about what the 'inverse' method does. The way ThomThom describes it, it sounds like an "undo" command.
-
Good example. I was thinking that in a limited way, but didn't fully appreciate the whole scale and rotation effect too. Good to know.
Hm. Seems like threads aren't hierarchical here. -
nope, just linear to keep it simple.
-
@billwheaton said:
Thanks Martin. And I read those and they were a great help, but I didn't find much there about what the 'inverse' method does.
I've never had occasion to use the
inverse()
method. I just use my Chapter 16 classes and theTransformation
class stays out of my life.
Advertisement