3
检测严格的顺时针/计数器clockwse运动我需要编写一个小程序,其测试线路(位置矢量)是否确实严格顺时针或CCLW运动。我试图使用atand来找到角度,但当它通过90度时,它可能会从负值跳到正值,如果使用斜率法,它也会有相同的结果。如何在MATLAB
然而,运动不具有在90度切割,它可以从89到91跳然后一个大坡跳可能发生。任何想法请
为此感谢
检测严格的顺时针/计数器clockwse运动我需要编写一个小程序,其测试线路(位置矢量)是否确实严格顺时针或CCLW运动。我试图使用atand来找到角度,但当它通过90度时,它可能会从负值跳到正值,如果使用斜率法,它也会有相同的结果。如何在MATLAB
然而,运动不具有在90度切割,它可以从89到91跳然后一个大坡跳可能发生。任何想法请
为此感谢
的一种方法是,计算连续的位置矢量的交叉产物。如果所有的交叉产品都是正的,那么这条线严格顺时针移动。同样,如果它们全部为负,那么该线逆时针移动。如果招牌混合然后行并没有在一个角方向严格移动:
>> pos = 20 * rand([10, 2]) - 10 pos = -8.28968405819912 9.26177078573826 -4.75035530603335 0.936114374779359 6.02029245539477 0.422716616080031 -9.41559444875707 -5.36811226582952 8.57708278956089 -0.222045121596661 4.60661725710906 2.48120176347379 -0.227820523928417 3.58271081731495 1.57050122046878 -2.08969568662814 -5.25432840456957 -2.65126702911047 -0.823023436401378 9.75964006323266 >> checkRotation(pos) No strict rotation direction
创建仅移动位置向量:
function checkRotation(pos)
pos(:,3) = 0;
pos = unique(sum(sign(cross(pos(1:end-1,:), pos(2:end,:))), 2));
if isequal(pos, 1)
disp('Rotation was counter-clockwise');
elseif isequal(pos, -1)
disp('Rotation was clockwise');
else
disp('No strict rotation direction');
end
上-10<=x<=10
和-10<=y<=10
和测试旋转创建一些随机的位置矢量CCW和测试:
>> theta = 0:15:180; >> pos = [cosd(theta)' sind(theta)']; >> checkRotation(pos) Rotation was counter-clockwise
,同样用于顺时针旋转:
>> theta = 180:-15:0; >> pos = [cosd(theta)' sind(theta)']; >> checkRotation(pos) Rotation was clockwise
请注意,旋转检测的成功受限于采样率。如果线在连续的线位置采样中逆时针旋转超过180度,则顺时针方向与小于180度的旋转不可区分。这是aliasing的一个例子。
我喜欢它。你很聪明。非常聪明......... – Marco