Rotate X,Y by Theta degrees about Xo,Yo.
It seems I often want to rotate a set of points. I usually want to rotate about some point (Xo,Yo) by a certain angle expressed in units of DEGREES. The routine here does that. When I run it with no arguments it tells me useful stuff:
Usage: xyrotate.sh 66.0 0.0 0.0 120.0 -450
arg1 - rotation angle in degrees (- for CCW, + for CW)
arg2 - Xo of rotation center
arg3 - Yo of rotation center
arg4 - X to be transformed
arg5 - Y to be transformed
% xyrotate.sh 20.0 100 100 100 120
106.840 118.794
% xyrotate.sh -20.0 100 100 100 120
93.160 118.794
% xyrotate.sh 20.0 100 100 120 100
118.794 93.160
% xyrotate.sh 20.0 100 100 80 80
74.366 88.047
An example of running some of the above coordinates in a list
form is shown below:
Usage: rotate_list list.1 30.0 1.0 -1.0
arg1 - name of file with list of x,y
arg2 - rotation angle in degrees (- for CCW, + for CW)
arg3 - x rotation center, Xo
arg4 - y rotation center, Yo
% cat dat.1
100.0 120.0
120.0 100.0
80.0 100.0
80.0 80.0
% rotate_list dat.1 +20.0 100.0 100.0
% rotate_list dat.1 +20.0 100.0 100.0
106.840 118.794
118.794 93.160
81.206 106.840
74.366 88.047
% rotate_list dat.1 -20.0 100.0 100.0
93.160 118.794
118.794 106.840
81.206 93.160
88.047 74.366
Notice that in this simple example I am rotating through
only a small angle. My input points are at easy locations
on the unit circle, and so I can quickly verify that I have indeed
rotated my points in a clockwise direction (beacues I use a POSITIVE
angle).
Just to be totally anal retentive, how about a plot:
% head list.1 -3694.7822 4416.2168 -3247.4417 4426.0132 -2796.8501 4432.3755 -2341.5298 4445.8818 (and on to 448) % rotate_list list.1 3.0 0 0 > list.2 % xyrotate.py list.1 list.2 -5000 5000 -5000 5000 % display plot.pngHere, using the nice legend in the upper-right corner of my plot, I would prove to myself that I had indeed rotate the point about 0,0 by 3 degrees in a clockwise direction.