- 积分
- 22798
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-12-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 葫芦爷儿 于 2019-1-11 22:11 编辑
群里有人问到了这样的船舶如何画,见图1。我是这样做,1 得到图像的外形,写入ship函数 2 获取目标位置信息、航首向信息 3 通过旋转矩阵对ship进行变形 4画图
其中3的步骤是:
- 利用M矩阵平移图形中心到原点
- 利用M1矩阵根据heading进行旋转
- 利用M2矩阵平移至坐标点
得到结果如图2.
参考网址:https://blog.csdn.net/zhang11wu4/article/details/49761121
https://blog.csdn.net/Bryan_QAQ/article/details/78805201
参考网址中有欧拉公式;在ship.m有说明;附件ship测试.zip 里有函数、测试数据、测试脚本。如有错误,感谢指正~
调用方法:- index =100;
- sta =250;
- longtitude_use = longitude(sta:end-index);
- latitude_use = latitude(sta:end-index);
- heading_use = heading(sta:end-index);
- %plot(longtitude_use,latitude_use,'r')
- hold on
- for index = 1:1:length(heading_use)
- ship(heading_use(index),longtitude_use(index),latitude_use(index), 0.00003)
- end
- axis equal
复制代码
图1 目标效果
图2 结果
- % 本程序画个小船…
- % 输入数据 :longitude,latitude,theta, scale
- % 分别是经度、纬度、船首向(deg),船相对大小
- % 思路:1 船的形状 2 先平移动到原点 3 旋转矩阵 4 平移到实际位置
- %
- % 调用方式:
- % for index = 1:5:length(heading)
- % ship(heading(index),longtitude(index),latitude(index), 0.00003)
- % end
- % 参考网址:https://blog.csdn.net/zhang11wu4/article/details/49761121
- % https://blog.csdn.net/Bryan_QAQ/article/details/78805201
- % 作者:葫芦爷儿
- % 联系方式 719087413@qq.com
- function ship(theta, longitude, latitude,scale)
- % 船的形状
- shipy = -scale.*([1, 3, 5, 7, 15, 15, 7, 5, 3, 1]-8);
- shipx = -scale.*([8, 9, 10, 11, 11, 5, 5, 6, 7, 8]-8);
- % 船的中心
- center_point = -scale.* [8,8];
- % heading转换弧度
- theta = pi*theta/180;
- %% 平移到原点,因为shipy-8,已经平移了
- M=[1 0 0;
- 0 1 0;
- 0 0 1;];
- R(1,:)=shipx;
- R(2,:)=shipy;
- R(3,:)=1;
- R1=M*R;
- %% 旋转矩阵
- M1=[cos(theta) sin(theta) 0;
- -sin(theta) cos(theta) 0;
- 0 0 1];
- R2=M1*R1;
- %% 平移到实际位置
- M3=[1 0 longitude;
- 0 1 latitude;
- 0 0 1;];
- R3=M3*R2;
- plot(longitude, latitude,'ko','MarkerFaceColor','k','MarkerSize',2)
- plot(R3(1,:), R3(2,:),'k')
复制代码
|
-
-
-
-
ship测试.zip
8.35 KB, 阅读权限: 10, 下载次数: 13, 下载积分: 金钱 -5
评分
-
查看全部评分
|