Download (as "rotate.pm") rotate.pm
# -*- Perl -*-
package rotate;
sub rotate ($$$) {
my ($x) = shift;
my ($y) = shift;
my ($angle) = shift; # in degree
# ------------------------------------------------
# X cos(theta) -sin(theta) x
# =
# Y sin(theta) cos(theta) y
# ------------------------------------------------
my ($theta) = $angle * 3.14159265 /180;
## https://mathwords.net/heimenkaiten
my ($X) = $x * cos($theta) + $y * - sin($theta);
my ($Y) = $x * sin($theta) + $y * cos($theta);
return ($X, $Y);
}
1;
|