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
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
2019-9-12
编辑:James Mathew
2019-9-12
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!