#!/usr/bin/perl -w

use strict;

sub Usage($@) {
    my $num = shift;
    print(@_);
    exit($num);
}

my $cx = shift;
my $cy = shift;
my $ang  = shift;
my $x = shift;
my $y = shift;

Usage(0, "rotate cx cy ang x y\n")  unless (defined($y));
my $pi = 2*atan2(1,0);

if ($ang =~ m/:/) {
    my @fld = split(/:/, $ang);
    $ang = 180/$pi * atan2($fld[1], $fld[0]);
    printf("Angle = %d\n", $ang + 0.5);
}

my $rad = $pi*$ang/180;
my $ca = cos($rad);
my $sa = sin($rad);
#printf("%7.5f %5.3f %5.3f\n", $pi, $ca, $sa);

sub rot($$) {
    my $x = shift;
    my $y = shift;

    my $X = $x * $ca + $y * $sa;
    my $Y = - $x * $sa + $y * $ca;
    ( $X, $Y );
}

my $dx = $x - $cx;
my $dy = $y - $cy;
my ($X, $Y) = rot($dx, $dy);

printf("%d %d\n", $X + $cx + 0.5, $Y + $cy + 0.5);
