如何找到两个坐标之间的航向角
56次观看(过去30天)
显示旧的注释
接受的答案
卡里姆
2023年1月12日
请参阅下面的一种方法
%随机生成机器人的点位置和方向
currPos = 1+10*(rand(1,2));% x-y坐标
currAng = pi*rand(1,1);%当前航向
current_direction = [cos(currAng) sin(currAng) 0];为当前方向创建向量
Current_direction = Current_direction ./√(sum(Current_direction . sum)^ 2));规格化向量
%机器人的目标点
targetPos = [4,5];
现在确定当前标题和目标位置之间的角度
target_direction = [targetPos - currPos 0];
Target_direction = Target_direction ./√(sum(Target_direction . sum)^ 2));规格化向量
最后确定两个方向之间的夹角。
delta = atan2(norm(cross(target_direction,current_direction)), dot(target_direction,current_direction)))
可视化状态
数字
持有在
散射(targetPos (1) targetPos(2), 100年,“r”,“填充”)
散射(currPos (1) currPos(2), 100年,‘g’,“填充”)
箭袋(currPos (1) currPos (2), current_direction (1) current_direction (2),“颜色”,“k”,“线宽”, 1.5,“MaxHeadSize”5)
箭袋(currPos (1) currPos (2), target_direction (1) target_direction (2),“颜色”,“r”,“线宽”, 1.5,“MaxHeadSize”5)
持有从
网格在
传奇(的目标位置,“机器人的位置”,“当前标题”,“目标标题”,“位置”,“最佳”)
轴平等的