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

Jan
Jan 2019년 9월 11일
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?
James Mathew
James Mathew 2019년 9월 12일
편집: James Mathew 2019년 9월 12일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2019년 9월 11일

편집:

2019년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by