C#绘制传感器代码

//以下代码添加到任一窗口下即可
        private int 旋转角度 = 0;
        private int 边长 = 10;
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            DrawSensor(e.Graphics, new Point(200, 200), 旋转角度, 边长);
        }
        /// <summary>
        /// 应力传感器代码,其他类型自己修改字符串值
        /// </summary>
        /// <param name="g"></param>
        /// <param name="p">三角形顶点坐标</param>
        /// <param name="sinta">旋转角度(顺时针正,逆时针负)</param>
        /// <param name="a">边长</param>
        private void DrawSensor(Graphics g,Point p,int sinta ,int a)
        {
            //设置线条平滑
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen=new Pen(Color.Black);
            pen.StartCap=pen.EndCap=LineCap.Round;
            pen.LineJoin = LineJoin.Round;
            //应力传感器符号p
            PointF Pstr=new PointF((float)p.X+((float)a)/2f*(float)Math.Cos(Math.PI*((float)sinta )/180f)-5f,(float)p.Y+((float)a)/2f*(float)Math.Sin(Math.PI*((float)sinta )/180f)-5f);
            g.DrawString("p", new Font("楷体_GB2312", 10), new SolidBrush(Color.FromArgb(0xff, 0xff, 0, 0)),Pstr);
            //方框所在圆半径
            double r = ((double)a) / Math.Sqrt(2);
            //方框中心坐标
            Point Po = new Point(p.X + (int)((a * Math.Sqrt(3) / 2d + a / 2d) * Math.Cos(Math.PI * sinta / 180d)), p.Y + (int)((a * Math.Sqrt(3) / 2d + a / 2d) * Math.Sin(Math.PI * sinta / 180d)));
            //三角形顶点坐标
            Point Ao = p;
            Point Bo = new Point(Po.X + (int)(r * Math.Cos(Math.PI * (225d + sinta) / 180d)), Po.Y + (int)(r * Math.Sin(Math.PI * (225d + sinta) / 180d)));
            Point Co = new Point(Po.X + (int)(r * Math.Cos(Math.PI * (135d + sinta) / 180d)), Po.Y + (int)(r * Math.Sin(Math.PI * (135d + sinta) / 180d)));
            Point Do = new Point(Po.X + (int)(r * Math.Cos(Math.PI * (315d + sinta) / 180d)), Po.Y + (int)(r * Math.Sin(Math.PI * (315d + sinta) / 180d)));
            Point Eo = new Point(Po.X + (int)(r * Math.Cos(Math.PI * (45d + sinta) / 180d)), Po.Y + (int)(r * Math.Sin(Math.PI * (45d + sinta) / 180d)));
            Point[] lp = new Point[] { Ao,Bo,Do,Eo,Co };
            g.DrawPolygon(pen,lp );
            g.DrawLine(pen,Co,Bo);
            g.DrawLine(pen, Co, Do);
        }

//传感器符号标准请查阅 http://www.myltem.com/use%5CGBT14479-1993.PDF

 

posted @ 2013-09-10 09:23  teyond  阅读(728)  评论(0编辑  收藏  举报