Rotational (angular) error between two trajectories

Hi,
I am trying to calculate rotational(angular) error between two trajectories. One trajectory is made by the target and the second is made by the curser. Ideally curser is supposed to track the target and two trajectories should be same. But due to inaccuracy in tracking, curser is always lagging behind target. I would like to calculate angular error between target and curser at each time point. For eg, my code looks like this:
%%
Tx is target array of 10000 samples (sampling freq = 1000)
Cx is curser array of 10000 samples
% target velocity
Vef_TrajX = diff(Tx)*1000;
Vef_TrajY = diff(Ty)*1000;
% Find indices according to velocity vector
in1 = find(Vef_TrajX>0); % X+
in2 = find(Vef_TrajX<0); % X-
in3 = find(Vef_TrajY>0); % Y+
in4 = find(Vef_TrajY<0); % Y-
% Group indices according to velocity vector
Q1 = intersect(in1,in3) ; % X+Y+ (0-90deg)
Q2 = intersect(in1,in4) ; % X+Y- (90-180 deg)
Q3 = intersect(in2,in3) ; % X-Y+ (270-360 deg)
Q4 = intersect(in2,in4) ; % X-Y- (180-270 deg)
% Calculate angle according to the group of velocity vectors
angleT(Q1) = atan(Vef_TrajY(Q1)./Vef_TrajX(Q1))*180./pi;
angleT(Q2) = -(atan(Vef_TrajY(Q2)./Vef_TrajX(Q2)).*180./pi)+90;
angleT(Q3) = -(atan(Vef_TrajY(Q3)./Vef_TrajX(Q3)).*180./pi)+270;
angleT(Q4) = (atan(Vef_TrajY(Q4)./Vef_TrajX(Q4)).*180./pi)+180;
% curser velocity
Vef_Cx = diff(Cx)*1000;
Vef_Cy = diff(Cy)*1000;
% Find indices according to velocity vector
in1 = find(Vef_Cx>0); % X+
in2 = find(Vef_Cx<0); % X-
in3 = find(Vef_Cy>0); % Y+
in4 = find(Vef_Cy<0); % Y-
% Group indices according to velocity vector
Q1 = intersect(in1,in3) ; % X+Y+ (0-90deg)
Q2 = intersect(in1,in4) ; % X+Y- (90-180 deg)
Q3 = intersect(in2,in3) ; % X-Y+ (270-360 deg)
Q4 = intersect(in2,in4) ; % X-Y- (180-270 deg)
% Calculate angle according to the group of velocity vectors
angle(Q1) = atan(Vef_BallY(Q1)./Vef_BallX(Q1))*180./pi;
angle(Q2) = -(atan(Vef_BallY(Q2)./Vef_BallX(Q2)).*180./pi)+90;
angle(Q3) = -(atan(Vef_BallY(Q3)./Vef_BallX(Q3)).*180./pi)+270;
angle(Q4) = (atan(Vef_BallY(Q4)./Vef_BallX(Q4)).*180./pi)+180;
% angular difference
Error= mean(abs(angleT-angle))
However, I wonder the way I average at the end will remove all 0-360 degree circular effect.
Anyone recommend any short way to do it, please?
Thanks

2 Comments

Please use the possibility to format code. This improves the readability. Thanks.
The code is not clear: What is Tx, a, b, Ve_TrajX, Ty, ...? We cannot run the code or guess, what these variables are. I do not know, what an "angular error" is. "Target" and "cursor" sound like points, so how is the angle defined?
Thanks for pointing this out, I have edited the codes to make it more clear.Since the data is very large i cannot copy it. I tried to comment on the steps I used. What i am trying is to find instantaneous angular error, that is at each time point (t) Target and Curser have position coodinates and make vectors with the future((t+1) position. In ideal case these vectors are in the same direction and make same angle with a reference line, so angular error is zero. But practically not, I am trying to find the difference in the angle these vectors make at every time point.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 11 Sep 2019

Edited:

on 12 Sep 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!