I am seeing the Geom::Transformation class’s inverse method not work correctly for a specific skew/shear situation.

The Ruby code I am working with italicizes some text in the X-Y plane with the following transformation:

```
shear_array = [ 1,0,0,0, 1,1,0,0, 0,0,1,0, 0,0,0,1 ]
h = Geom::Transformation.new( shear_array )
```

Now I can apply transformation “h” to my component instance with “transform!” to shear it. That is working correctly.

I can obtain a string object that provides the transformation matrix values in column major order with the following method:

```
def tmatrix_bycolumn( transformation )
ma = transformation.to_a.collect{|value| "%8.3f" % value }
result = " #{ma[ 0]}, #{ma[ 4]}, #{ma[ 8]}, #{ma[12]}\n"
result << " #{ma[ 1]}, #{ma[ 5]}, #{ma[ 9]}, #{ma[13]}\n"
result << " #{ma[ 2]}, #{ma[ 6]}, #{ma[10]}, #{ma[14]}\n"
result << " #{ma[ 3]}, #{ma[ 7]}, #{ma[11]}, #{ma[15]}\n"
return result
end
```

I can output with a statement like:

`puts tmatrix_bycolumn( h * h.inverse)`

The results are:

```
1.000, 0.000, 0.000, 0.000
0.000, 1.000, 0.000, 0.000
0.000, 0.000, 1.000, 0.000
0.000, 0.000, 0.000, 1.000
```

The output is the identity matrix, indicating that the inverse was calculated correctly.

But, constructing this transformation with normalized “h” matrix axes and taking the inverse results in an incorrect inverse. Initialization and output statement below:

```
skew = Geom::Transformation.axes( ORIGIN, h.xaxis, h.yaxis, h.zaxis )
puts tmatrix_bycolumn( skew * skew.inverse )
```

The output is:

```
1.500, 0.500, 0.000, 0.000
0.500, 0.500, 0.000, 0.000
0.000, 0.000, 1.000, 0.000
0.000, 0.000, 0.000, 1.000
```

The result is not identity, even though this type of skew is a valid transformation matrix.

Sketchup’s Geom module’s transformation class’s inverse for the skew is:

`Puts tmatrix_bycolumn( skew.inverse )`

```
1.000, 0.000, 0.000, -0.000
0.707, 0.707, 0.000, -0.000
0.000, 0.000, 1.000, -0.000
0.000, 0.000, 0.000, 1.000
```

The correct result from Octave (an open source type Matlab console) is:

```
1.00000 -1.00000 -0.00000 -0.00000
0.00000 1.41443 -0.00000 -0.00000
0.00000 0.00000 1.00000 -0.00000
0.00000 0.00000 0.00000 1.00000
```

You can also try an online matrix calculator like: Matrix calculator

The only difference between the one that works and the one that does not is that the one that works is scaled.

I realize that skews/shears are uncommon, but it looks like inverse isn’t working for all types of matrices.

Note: Matrix inverse was discussed at:

But that topic was about non-invertible transformaitons.