Version 4 of Vector rotations with Bwise

Updated 2004-03-25 07:34:08

by Theo Verelst

A common thing in math and science is the rotation of a vector over an angle, as most with a math basis knowledge will know, a matrix can be used for the purpose of performing the rotation on a vector.

A rotation matrix is even a very well formed matrix in general with normally excellent invertability and eigenvalue computability.

It is not hard to make a orthogonal and even orthonomal basis for both the column and row space of a 2 dimensional matrix, and we can do so symbolically with simple geometic functions with a single rotation angle as a parameter for each of the 2x2 matrix elements which determines the rotation the matrix performs when multiplied to a vector.

Clear application is computer graphics, but other computations, for instance where complex numbers are used such as in electronics or other solutions of differential equations, also can become more insightfull by clear (simple) vector representations.

Bwise is about BlockWise programming, and also about Tk canvasses with interactions and graphical feedback, so this is a nice example.

In tcl, without using anything specifically from the Bwise package, except I used the function window, and will use the 'create block' facility of it, the rotation of a 2 dimensional (2 real components obviously quantized to some computer number resolution) vector can be performed by:

 proc vec2rot { x y a } {
   set     rotor.out [ expr cos($a) *$x  - sin($a) *$y ]
   lappend rotor.out [ expr sin($a) *$x  + cos($a) *$y ]
 }

When this procedure is defined, procs_window from bwise can be used to blockify our procedure. First, refresh the list of procs, then double click vec2rot, and then press the ' block' button on the bottom. First, a block on the canvas will be generated with name 'vec2rot'. When pressed again, serial numbers are added to the name, based on the highest appearing serial number on the canvas thus far. I double clicked and 'del sel' (deleted) the first instance of the block after clicking into existence two more, so I have vec2rot1 and vec2rot2 .

The procedure, like any, has only one return value, which is a list.

So we define for the sake of the Bwise canvas we have in mind a seperate block, which splits a 2-long list into elements for to two output pins. We use the newproc bwise proc to generate a 2 output block, possibly using the pro_args functions, which automatically puts arguments in place for the newproc, which gets default arguments except for name and output names x and y.

   pro_args  newproc {{name {sep1}}  {out {x y}}}

Gives:

   newproc {} sep1 in {x y}

Either using eval on the pro_args or simply issuing the newproc command a seperator block is created which is given list-split block function code, and connected to the ouput of the rotation block by either command or UI:

   set sep1.bfunc {set sep1.x [lindex ${sep1.in} 0] ; set sep1.y [lindex ${sep1.in} 1] }

http://82.168.209.239/Wiki/rotor1.jpg