爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5170|回复: 3

[程序设计] plot以船形状画点

[复制链接]

新浪微博达人勋

发表于 2019-1-11 21:40:51 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

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 里有函数、测试数据、测试脚本。如有错误,感谢指正~

调用方法:
  1. index =100;
  2. sta =250;
  3. longtitude_use = longitude(sta:end-index);
  4. latitude_use = latitude(sta:end-index);
  5. heading_use = heading(sta:end-index);
  6. %plot(longtitude_use,latitude_use,'r')
  7. hold on
  8. for index  = 1:1:length(heading_use)
  9.     ship(heading_use(index),longtitude_use(index),latitude_use(index), 0.00003)
  10. end
  11. axis equal
复制代码
目标图片.png
图1 目标效果


结果图片.png

图2 结果


  1. % 本程序画个小船…
  2. % 输入数据 :longitude,latitude,theta, scale
  3. %                     分别是经度、纬度、船首向(deg),船相对大小
  4. % 思路:1 船的形状 2 先平移动到原点 3 旋转矩阵 4 平移到实际位置
  5. %
  6. % 调用方式:
  7. % for index  = 1:5:length(heading)
  8. %     ship(heading(index),longtitude(index),latitude(index), 0.00003)
  9. % end
  10. % 参考网址:https://blog.csdn.net/zhang11wu4/article/details/49761121
  11. %                      https://blog.csdn.net/Bryan_QAQ/article/details/78805201
  12. % 作者:葫芦爷儿  
  13. % 联系方式 719087413@qq.com

  14. function ship(theta, longitude, latitude,scale)
  15. % 船的形状
  16. shipy = -scale.*([1, 3, 5, 7, 15, 15, 7, 5, 3, 1]-8);
  17. shipx = -scale.*([8, 9, 10, 11, 11, 5, 5, 6, 7, 8]-8);
  18. % 船的中心
  19. center_point = -scale.* [8,8];
  20. % heading转换弧度
  21. theta = pi*theta/180;
  22. %%  平移到原点,因为shipy-8,已经平移了
  23. M=[1    0     0;
  24.        0    1     0;
  25.        0    0     1;];
  26. R(1,:)=shipx;
  27. R(2,:)=shipy;
  28. R(3,:)=1;
  29. R1=M*R;
  30. %% 旋转矩阵
  31. M1=[cos(theta)   sin(theta)     0;
  32.     -sin(theta)   cos(theta)    0;
  33.         0           0         1];
  34. R2=M1*R1;
  35. %% 平移到实际位置
  36. M3=[1    0    longitude;
  37.        0    1     latitude;
  38.        0    0     1;];
  39. R3=M3*R2;
  40. plot(longitude, latitude,'ko','MarkerFaceColor','k','MarkerSize',2)
  41. plot(R3(1,:), R3(2,:),'k')
复制代码






结果图片.png
目标图片.png

ship测试.zip

8.35 KB, 阅读权限: 10, 下载次数: 12, 下载积分: 金钱 -5

评分

参与人数 2金钱 +30 贡献 +15 收起 理由
mofangbao + 20 + 10 挺有想法
二爷名声在外 + 10 + 5 很给力!

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-1-12 09:13:49 | 显示全部楼层
感谢分享十分给力
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-1-16 19:54:08 | 显示全部楼层
非常给力,感谢
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-3-7 11:37:49 | 显示全部楼层
没看懂这是干嘛用的
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表