月份信息二维坐标图绘制---(绘制箭头完美算法)续II

      今天中午,大家都在睡觉的时候,本人忙里偷闲找了点资料看了下,箭头算法终于到了最终版本了。非常感谢各位前辈在网上的资料,特别是MFC,JAVA的资料比较多。这里终于也可以告一段落了。

      以下是C#的箭头算法,源代码如下:

 1         ///   <summary>
 2           ///  绘制箭头
 3           ///   </summary>
 4           ///   <param name="graphics"></param>
 5           ///   <param name="startPoint"> 起始点 </param>
 6           ///   <param name="endPoint"> 终止点 </param>
 7           private   void  DrawArrowHead(Graphics graphics, PointF startPoint, PointF endPoint)
 8          {
 9               double  distance  =  Math.Abs(Math.Sqrt(
10                  (startPoint.X  -  endPoint.X)  *  (startPoint.X  -  endPoint.X)  +
11                  (startPoint.Y  -  endPoint.Y)  *  (startPoint.Y  -  endPoint.Y)));
12 
13               if  (distance  ==   0 )
14              {
15                   return ;
16              }
17 
18               double  xa  =  endPoint.X  +  ArrowLength  *  ((startPoint.X  -  endPoint.X)
19                   +  (startPoint.Y  -  endPoint.Y)  /  RelativeValue)  /  distance;
20               double  ya  =  endPoint.Y  +  ArrowLength  *  ((startPoint.Y  -  endPoint.Y)
21                   -  (startPoint.X  -  endPoint.X)  /  RelativeValue)  /  distance;
22               double  xb  =  endPoint.X  +  ArrowLength  *  ((startPoint.X  -  endPoint.X)
23                   -  (startPoint.Y  -  endPoint.Y)  /  RelativeValue)  /  distance;
24               double  yb  =  endPoint.Y  +  ArrowLength  *  ((startPoint.Y  -  endPoint.Y)
25                   +  (startPoint.X  -  endPoint.X)  /  RelativeValue)  /  distance;
26 
27              PointF[] polygonPoints  =
28                   new  PointF(endPoint.X , endPoint.Y), 
29                   new  PointF( ( float )xa   ,  ( float )ya),
30                   new  PointF( ( float )xb   ,  ( float )yb)};
31 
32              DrawArrowHead(graphics, polygonPoints);
33          }

 

 

1         private   static   void  DrawArrowHead(Graphics graphics, PointF[] points)
2          {
3              graphics.DrawPolygon(Pens.Red, points);
4              graphics.FillPolygon( new  SolidBrush(Color.Red), points);
5          }

 

 

      具体是通过终点Point的坐标,以及计算出的2个角的坐标,然后通过绘制多边形来绘制箭头。

 

显示效果如下:

 

       这个已经是最终版本的算法,误差几乎可以忽略。上面的方法是可以调用的,大家可以试下,希望能够对各位有所帮助..........

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值