0
$\begingroup$

Given I have a 2D affine transform described by the matrix:

[ a  c  tx ]
[ b  d  ty ]
[ 0  0  1  ]

Such that:

[ x ]   [ a  c  tx ] [ x ]   [ a * x + c * y + tx ]
[ y ] = [ b  d  ty ] [ y ] = [ b * x + d * y + ty ]
[ 1 ]   [ 0  0  1  ] [ 1 ]   [         1          ]

I have a shape that starts at [-(width/2), -(height/2)] so that it is centred about [0, 0].

I want to change the origin of the shape so that it starts at [0,0] but I want its transformed coordinates to be the same.

How do I update the matrix to map the objects new origin to the same end position?

I seem to be failing at the point where when x or y equals = 0 everything just cancels out and becomes:

[ tx ]
[ ty ]
[ 1  ]
  • 0
    The general form of an affin transformation is $y=Tx+b$, where $b$ is the translation vector. In your case $b$ depends on $x$, which is illegal.2017-01-13
  • 0
    @zoli I don't quite understand. This follows the formula given here: https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations and the result is just a multiplication of the two matrices. `b` In my formula affects rotation and skew along the y axis.2017-01-13

1 Answers 1

0

I realised the way to do this is to form a new matrix:

[ a  c  ox ]
[ b  d  oy ]
[ 0  0  1  ]

Where:

  • w = -(width / 2)
  • h = -(height / 2)
  • ox = tx + aw + ch
  • oy = ty + bw + dh