- theta = tile.get_angle_in_plan(i, j)
-
- # The transformation from a tile in the square to the correspondent
- # tile in the plan is composed by these steps:
- #
- # 1. rotate by 'theta' around (src_x, src_y);
- # 2. move to (dest_x, dest_y).
- #
- # Step 1 can be expressed by these sub-steps:
- #
- # 1a. translate by (-src_x, -src_y)
- # 1b. rotate by 'theta'
- # 1c. translate by (src_x, src_y)
- #
- # Step 2. can be expressed by a translation like:
- #
- # 2a. translate by (dest_x - src_x, dest_y - src_y)
- #
- # The consecutive translations 1c and 2a can be easily combined, so
- # the final steps are:
- #
- # T1 -> translate by (-src_x, -src_y)
- # R -> rotate by 'theta'
- # T2 -> translate by (dest_x, dest_y)
- #
- # Using affine transformations these are expressed as:
- #
- # | 1 0 -src_x |
- # T1 = | 0 1 -src_y |
- # | 0 0 1 |
- #
- # | cos(theta) -sin(theta) 0 |
- # R = | sin(theta) con(theta) 0 |
- # | 0 0 1 |
- #
- # | 1 0 dest_x |
- # T2 = | 0 1 dest_y |
- # | 0 0 1 |
- #
- # Composing these transformations into one is achieved by multiplying
- # the matrices from right to left:
- #
- # T = T2 * R * T1
- #
- # NOTE: To remember this think about composing functions: T2(R(T1())),
- # the inner one is performed first.
- #
- # The resulting T matrix is the one below.
- matrix = [
- cos(theta), -sin(theta), -src_x * cos(theta) + src_y * sin(theta) + dest_x,
- sin(theta), cos(theta), -src_x * sin(theta) - src_y * cos(theta) + dest_y,
- 0, 0, 1
- ]
-
- return matrix