# An Analog Clock

Despite not having to worry about internationalization of date and time strings, an analog clock is quite a bit more complex to code than the digital clock of the previous section. To code an analog clock, knowledge of the mapping modes and some trigonometry needs to be acquired. A snapshot of the analog clock running is shown below. By way of setting the mapping mode for the clock program, the function set_isotropic is shown below.

```void set_isotropic(handle device_context,
int width_of_client,
int height_of_client)
{
set_mapping_mode(device_context,unit::isotropic);
set_window_extent(device_context,1000,1000);
set_viewport_extent(device_context,width_of_client/2,-height_of_client/2);
set_viewport_origin(device_context,width_of_client/2, height_of_client/2);
}
```

The unit unit::Isotropic is set and the window extent is set to 1000 in both the x and y directions. The viewport of origin is set to be at the center of the client area and the viewport extent is set to be 1/2 the width of the client in the x-direction and -1/2 the height of the client area in the y-direction. This yields an isotropic, cartesian coordinate system centered within the client area of the window.

The function rotate_points rotates a specified array of points a given angle in the clockwise direction. The equations for rotating the point(x,y) through an angle 'a' (anticlockwise) are

```x' = x*cos(a) - y*sin(a);
y' = y*sin(a) + x*cos(a);
```

These are the standard linear algebra results obtained by a 2x2 matrix multiplication. To rotate clockwise, one must substitute -a for a to get:

```x' =  x*cos(a) + y*sin(a);  // noting that sin(-a) == -sin(a)
y' = -y*sin(a) + x*cos(a);  //        and  cos(-a) ==  cos(a)
```

These formulae are used in the function rotate_points shown below.

```void rotate_points(point point_array[],
int count,
int angle)
{
double radians = TwoPi * angle / 360;