Re: function for rotating set of points
- From: "Jon Ericson" <jonathan_eric-DELETETHI$-son@xxxxxxxxx>
- Date: Thu, 31 Jul 2008 17:52:02 +0000 (UTC)
I think I figured it out, for anyone who is interested...
=========
clear all
close all
start = [0 0]
actual = [10 0]
target = [11 15]
% create a translator matrix based on the start location
translator = [start(1)*-1 start(2)*-1];
% translate all the points so that start is at the origin
newstart = start + translator;
newactual = actual + translator;
newtarget = target + translator;
% plot the original points
figure
scatter(start(1),start(2), 'go');
axis ([-15 15 -15 15]);
hold on
scatter (actual(1),actual(2), 'bo');
scatter (target(1),target(2), 'ro');
% plot the translated points
figure
scatter (newstart(1),newstart(2), 'go');
axis ([-15 15 -15 15]);
hold on
scatter (newactual(1), newactual(2),'bo');
scatter (newtarget(1), newtarget(2),'ro');
% rotate the translated points so that the actual point is
on +x-axis
newactualrads = cart2pol(newactual(1),newactual(2)) % get
polar coord theta (radians) for actual location
newactualdegs = rad2deg(newactualrads) %
convert the polar coord to a degree value
% now that the actual point is on the x-axis, the target
point is either
% above, below, or on the x-axis (not likely). If the
target point is
% above the x-axis, the subject went to the right of the
target, and we
% will get an error in +degrees. If the target point is
below the x-axis,
% the subject went to the left of the target andwe will get
an error in -degrees.
% no matter what, we've already translated the start to
(0,0), so let's
% just be sure that it actually is (0,0)
finalstartx = 0
finalstarty = 0
if newactualdegs < 0 % if the target
is below the x-axis
newactualdegs = abs(newactualdegs) % use the
absolute value of the degree difference because the formulas
below do a CCW rotation
elseif newactualdegs > 0 % if the target
is above the x-axis
newactualdegs = 360-newactualdegs % rotate by 360
the angle for the same reason
elseif newactualdegs == 0
end
finalactualx = newactual(1) * cosd(newactualdegs) -
newactual(2) * sind(newactualdegs);
finalactualy = newactual(2) * cosd(newactualdegs) +
newactual(1) * sind(newactualdegs);
finaltargetx = newtarget(1) * cosd(newactualdegs) -
newtarget(2) * sind(newactualdegs);
finaltargety = newtarget(2) * cosd(newactualdegs) +
newtarget(1) * sind(newactualdegs);
% now plot the
figure
scatter(finalstartx, finalstarty, 'go')
axis ([-15 15 -15 15]);
hold on
scatter(finalactualx, finalactualy, 'bo')
scatter(finaltargetx, finaltargety, 'ro')
=========
If you play around with start, actual, and target
parameters, it seems to work no matter what...
.
- References:
- function for rotating set of points
- From: Jon Ericson
- function for rotating set of points
- Prev by Date: Re: Wavelet Transform Coeff Values
- Next by Date: Re: function for translating and rotating triangles/points
- Previous by thread: Re: function for rotating set of points
- Next by thread: function for translating and rotating triangles/points
- Index(es):
Relevant Pages
|