当前位置:   article > 正文

根据卫星仰角和方位角使用html5绘制天空图(投影图)_html5 图片投影

html5 图片投影


本文记录根据卫星仰角和方位角使用html5绘制天空图(投影图)。

也就是根据这两个角度绘制坐标点在圆形上的投影。


术语:

方位角:从标准方向的北端起,顺时针方向到直线的水平角称为该直线的方位角。方位角的取值范围为0°~360°。
仰角:视线在水平线以上时,在视线所在的垂直平面内,视线与水平线所成的角叫做仰角.

步骤:

1.绘制天空图背景。

2.根据仰角和方位角计算在canvas画布上的坐标。从而绘制图标以及文字。


原始数据:

type:数据类型、 num:卫星号 、 elevation:仰角 、(0-90)azimuth:方位角(0-360)

  1. //elevation仰角 azimuth方位角
  2. var drawData = [
  3. {"type":"1","num":81, "elevation":0, "azimuth":0 },
  4. {"type":"2", "num":2, "elevation":50, "azimuth":66 },
  5. {"type":"3", "num":3, "elevation":44, "azimuth":149 },
  6. {"type":"4", "num":33, "elevation":20, "azimuth":270 },
  7. {"type":"5", "num":45, "elevation":80, "azimuth":33},
  8. {"type":"6", "num":9, "elevation":60, "azimuth":270 },
  9. {"type":"4", "num":35, "elevation":80, "azimuth":333},
  10. {"type":"2", "num":77, "elevation":10, "azimuth":222 },
  11. {"type":"1", "num":64, "elevation":55, "azimuth":111 }
  12. ];

效果图:


第一步,绘制背景。依次画三个圈,实现同心圆。 然后通过旋转画布的方式来绘制切割圆的线条。切割圆的线条之间角度为30度。


背景绘制代码:

  1. // 绘制背景
  2. function drawBaseSky(){
  3. var cxt = document.getElementById('skyPic').getContext("2d");
  4. var radius = 180;//半径
  5. cxt.translate(15,15);//坐标原点移动,留出边界值,让可能出现在最外层的信息能显示
  6. //绘制背景
  7. cxt.beginPath();
  8. cxt.fillStyle = 'rgb(242,242,242)';
  9. cxt.arc(radius, radius, radius, 0, Math.PI*2, false);
  10. cxt.fill();
  11. cxt.beginPath();
  12. cxt.fillStyle ='white';
  13. cxt.arc(radius, radius, radius*2/3, 0, Math.PI*2, false);
  14. cxt.fill();
  15. cxt.beginPath();
  16. cxt.fillStyle = 'rgb(242,242,242)';
  17. cxt.arc(radius, radius, radius/3, 0, Math.PI*2, false);
  18. cxt.fill();
  19. cxt.save(); //保存状态
  20. //通过旋转的方式画圆中的分割线
  21. cxt.beginPath();
  22. cxt.strokeStyle = 'rgb(220,220,220)';
  23. cxt.translate(radius,radius);
  24. for(var i=0;i<12;i++){
  25. cxt.rotate(Math.PI/180*30);
  26. cxt.moveTo(0,0);
  27. cxt.lineTo(0,radius);
  28. }
  29. cxt.stroke();
  30. cxt.restore();
  31. }


第二步:计算在画布上的坐标。并将数据点投影绘制到天空图上。难点在于坐标计算。


  1. //绘制数据分布
  2. function drawSkyPosition(drawData){
  3. var color ={
  4. "1":"rgb(173,152,12)",
  5. "2":"rgb(75,164,259)",
  6. "3":"rgb(226,120,228)",
  7. "4":"rgb(117,173,61)",
  8. "5":"rgb(230,139,55)",
  9. "6":"rgb(61,168,161)"
  10. };
  11. var cxt = document.getElementById('skyPic').getContext("2d");
  12. var radius = 180;//半径
  13. var cosLen,x,y;
  14. cxt.save();
  15. cxt.translate(radius,radius);
  16. cxt.font = "bold 14px Arial";
  17. cxt.textAlign = "center";
  18. cxt.textBaseline = "middle";
  19. for(var i=0,dataLen = drawData.length;i<dataLen;i++){
  20. cxt.beginPath();
  21. cxt.fillStyle = color[drawData[i].type];
  22. //关键代码。求圆心坐标。coslen是求出来的该点到圆心的距离。
  23. var cosLen = Math.cos(drawData[i].elevation*Math.PI/180)*radius;
  24. y = Math.cos(drawData[i].azimuth*Math.PI/180)* cosLen;
  25. x = Math.sin(drawData[i].azimuth*Math.PI/180)* cosLen;
  26. cxt.arc(x,-y , 14, 0, Math.PI*2, false);//在坐标点绘制圆
  27. cxt.fill();
  28. cxt.beginPath();
  29. cxt.fillStyle ='white';
  30. cxt.fillText(drawData[i].num, x, -y);//在坐标点写文字卫星号
  31. }
  32. cxt.restore();
  33. }


ok,大功告成。

根据卫星方位角和仰角绘制天空图(投影图)介绍到这里。


演示地址:http://runningls.com/demos/2015/position/sky.html



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号