C#绘制传感器代码
2013-09-10 09:23
225 查看
//以下代码添加到任一窗口下即可
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
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
相关文章推荐
- C#语言绘制实时曲线图代码实例
- C#中绘制文字两套代码
- SkylineGlobe 6.5 如何实现简单多边形的动态绘制 C#示例代码
- atitit..代码生成流程图 流程图绘制解决方案 java c#.net php v2
- C#语言绘制实时曲线图代码实例
- C# Managed DirectX 三角形旋转(修改Direct 3D绘制流水线(渲染管线)中代码)
- atitit..代码生成流程图 流程图绘制解决方案 java c#.net php v2
- C#绘制条形码的代码
- 使用 SqlBulkCopy 大量复制文字文件之 C# 程序代码
- C#摄像头实现拍照功能的简单代码示例
- 【OpenCV 学习】自带示例:随机数发生器&绘制文字 代码注释解析
- C# TreeView CheckBox 代码挑勾选中
- C# Chart控件,chart、Series、ChartArea曲线图绘制的重要属性
- Windows系统中C#读写ini配置文件的程序代码示例分享
- 一个统计代码行数的程序C#
- C# 程序到期将时间写入注册表代码
- C#代码、流程discuz论坛批量或自动发帖
- 转: 编写高质量代码改善C#程序的157个建议
- C# 操作PostgreSQL 数据库的示例代码
- [Eclipse笔记]Just for fun – 在Eclipse下编译和运行C#的代码