Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#1180) [PATCH] cleanup to canvas_pos_to_map_pos
Home

[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]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#1180) [PATCH] cleanup to canvas_pos_to_map_pos
From: "Gregory Berkolaiko via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 19 Nov 2002 12:56:43 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[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.

PNG image


[Prev in Thread] Current Thread [Next in Thread]