[Freeciv-Dev] (PR#1180) [PATCH] cleanup to canvas_pos_to_map_pos
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
[rwetmore@xxxxxxxxxxxx - Tue Jan 1 22:11:02 2002]:
> First, what one really *wants* to do is a simple pi/4 rotation. Which
> mathematically looks like ...
>
> | 1 1 | |x| |x`|
> | | | | -> | |
> |-1 1 | |y| |y`|
>
> ... plus a scaling operation because canvas coordinates are a finer
> granularity than tile (plus a coordinate origin translation).
>
> But the latter is complicated if the x and y scaling factors are not
> the same, or conversely the rotation would not be a simple pi/4 but
> something like (note these are the mathematically correct sin/cos
> values) ...
>
> | N_T_H/(N_T_H*N_T_W) N_T_W/(N_T_H*N_T_W) | |x| |x`|
> | | | | -> | |
> |-N_T_H/(N_T_H*N_T_W) N_T_W/(N_T_H*N_T_W) | |y| |y`|
So, skipping N_T_ stuff and cancelling the common factors, the
transformation is
x_map = [ x / W + y / H]
y_map = [ y / H - x / W]
where [q] stands for integer part of q. Here the division is proper
mathematical floating point division.
Note that this for is effectively the pi/2 rotation, but first the x and
y coodinates have to be expressed in the units of Width and Height of
the tile.
To illustrate how the transformation works, here is a picture.
G.
|
|