It is currently March 28th, 2024, 8:15 pm

Having trouble with transformation matrices

Get help with creating, editing & fixing problems with skins
AndrewBot88
Posts: 14
Joined: June 23rd, 2012, 11:28 pm

Having trouble with transformation matrices

Post by AndrewBot88 »

So I'm trying to elongate a square to twice its height, then rotate it clockwise 30 degrees centered on its bottom-middle point. The square is 50x50 in the center of a 300x300 background. My first matrix (A) is the scaling:

Code: Select all

1 0 0
0 2 -175
0 0 1
This does what it should, extending the square upwards. Next is the rotating (B):

Code: Select all

0.866  0.5    108
-0.5   0.866  -52
0      0      1
This also works properly, rotating the square clockwise and keeping it anchored on the center-bottom point. This is the matrix I get from multiplying B*A (using multiple online calculators):

Code: Select all

0.866  1     20
-0.5   1.732 -203
0      0     1
But that gives me this image:
Image
Multiplying A*B gives the correct shape but in the wrong position, and I believe that's the wrong way to multiply them anyway.

My complete skin can be seen here, if that would help:
[MeterBG]
Meter=IMAGE
w=300
h=300
SolidColor=200,200,255,255
[MeterSquare]
Meter=IMAGE
w=50
h=50
x=125
y=125
SolidColor=0,0,0
;TransformationMatrix=1;0;0;2;0;-175 ; (Scaling matrix)
;TransformationMatrix=0.8660;0.5;-0.5;0.8660;108;-52 ; (Rotating matrix)
;TransformationMatrix=0.866;1;-0.5;1.732;20;-203 ; (Final matrix)
Does anybody have some insight that could help?
Last edited by AndrewBot88 on January 13th, 2017, 12:15 am, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Having trouble with transformation matrices

Post by balala »

The transformation matrix, if used correctly, is indeed an extremely "powerful" tool. But in this case, there is an error in your approach: this error is the order of the numbers you're copying from the matrix, to the appropriate Rainmeter option.
Eg the TransformationMatrix=0.8660;0.5;-0.5;0.8660;108;-52 option, written to a matrix, would be:

Code: Select all

0.866   -0.5     108
0.5     0.866   -52
0       0       1
not as you wrote initially:

Code: Select all

0.866   0.5     108
-0.5    0.866   -52
0       0       1
According to this, you didn't multiply together the proper matrices. If you redo the calculations, you'll get the following matrix: TransformationMatrix=0.866;0.5;-1;1.732;200;-204. I got this one multiplying together the following two matrices: TransformationMatrix=0.8660;0.5;-0.5;0.8660;108;-52 and TransformationMatrix=1;0;0;2;0;-175.
AndrewBot88
Posts: 14
Joined: June 23rd, 2012, 11:28 pm

Re: Having trouble with transformation matrices

Post by AndrewBot88 »

Dammit, I knew it was going to be some stupid mistake like that; that's what I get for working with matrices at like 11pm. Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Having trouble with transformation matrices

Post by balala »

Working with matrices can be hard to make common mistakes sometimes. Glad to help if I can.