C#画坐标系

作者: 此十八 | 来源:发表于2018-03-02 16:16 被阅读60次

using System;  

using System.Collections.Generic;  

using System.Linq;  

using System.Text;  

using System.Threading.Tasks;  

using System.Windows.Forms;  

using System.Drawing;    

namespace 坐标1  

{  

class XYlinesFactory  

    {  

        #region   画出X轴与Y轴  

///     

/// 在任意的panel里画一个坐标,坐标所在的四边形距离panel边50像素    

///     

///     

public void DrawXY(Panel pan)  

        {  

            Graphics g = pan.CreateGraphics();  

//整体内缩move像素    

float move = 50f;  

float newX = pan.Width - move;  

float newY = pan.Height - move;  

//绘制X轴,    

PointF px1 =new PointF(move, newY);  

PointF px2 =new PointF(newX, newY);  

g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);  

//绘制Y轴    

PointF py1 =new PointF(move, move);  

PointF py2 =new PointF(move, newY);  

g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);  

        }  

        #endregion  

///     

/// 画出Y轴上的分值线,从零开始    

///     

///     

///     

///     

        #region   画出Y轴上的分值线,从零开始  

public void DrawYLine(Panel pan, float maxY, int len)  

        {  

float move = 50f;  

float LenX = pan.Width - 2 * move;  

float LenY = pan.Height - 2 * move;  

            Graphics g = pan.CreateGraphics();  

for (int i = 0; i <= len; i++)    //len等份Y轴    

            {  

PointF px1 =new PointF(move, LenY * i / len + move);  

PointF px2 =new PointF(move + 4, LenY * i / len + move);  

string sx = (maxY - maxY * i / len).ToString();  

g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);  

StringFormat drawFormat =new StringFormat();  

                drawFormat.Alignment = StringAlignment.Far;  

                drawFormat.LineAlignment = StringAlignment.Center;  

g.DrawString(sx,new Font("宋体", 8f), Brushes.Black, new PointF(move / 1.2f, LenY * i / len + move * 1.1f), drawFormat);  

            }  

Pen pen =new Pen(Color.Black, 1);  

g.DrawString("Y轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(move / 3, move / 2f));  

        }  

        #endregion  

///     

/// 画出Y轴上的分值线,从任意值开始    

///     

///     

///     

///     

///     

        #region   画出Y轴上的分值线,从任意值开始  

public void DrawYLine(Panel pan, float minY, float maxY, int len)  

        {  

float move = 50f;  

float LenX = pan.Width - 2 * move;  

float LenY = pan.Height - 2 * move;  

            Graphics g = pan.CreateGraphics();  

for (int i = 0; i <= len; i++)    //len等份Y轴    

            {  

PointF px1 =new PointF(move, LenY * i / len + move);  

PointF px2 =new PointF(move + 4, LenY * i / len + move);  

string sx = (maxY - (maxY - minY) * i / len).ToString();  

g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);  

StringFormat drawFormat =new StringFormat();  

                drawFormat.Alignment = StringAlignment.Far;  

                drawFormat.LineAlignment = StringAlignment.Center;  

g.DrawString(sx,new Font("宋体", 8f), Brushes.Black, new PointF(move / 1.2f, LenY * i / len + move * 1.1f), drawFormat);  

            }  

Pen pen =new Pen(Color.Black, 1);  

g.DrawString("Y轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(move / 3, move / 2f));  

        }  

        #endregion  

///     

/// 画出X轴上的分值线,从零开始    

///     

///     

///     

///     

        #region   画出X轴上的分值线,从零开始  

public void DrawXLine(Panel pan, float maxX, int len)  

        {  

float move = 50f;  

float LenX = pan.Width - 2 * move;  

float LenY = pan.Height - 2 * move;  

            Graphics g = pan.CreateGraphics();  

for (int i = 1; i <= len; i++)  

            {  

PointF py1 =new PointF(LenX * i / len + move, pan.Height - move - 4);  

PointF py2 =new PointF(LenX * i / len + move, pan.Height - move);  

string sy = (maxX * i / len).ToString();  

g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);  

g.DrawString(sy,new Font("宋体", 8f), Brushes.Black, new PointF(LenX * i / len + move, pan.Height - move / 1.1f));  

            }  

Pen pen =new Pen(Color.Black, 1);  

g.DrawString("X轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(pan.Width - move / 1.5f, pan.Height - move / 1.5f));  

        }  

        #endregion  

        #region   画出X轴上的分值线,从任意值开始  

///     

/// 画出X轴上的分值线,从任意值开始    

///     

///     

///     

///     

///     

public void DrawXLine(Panel pan, float minX, float maxX, int len)  

        {  

float move = 50f;  

float LenX = pan.Width - 2 * move;  

float LenY = pan.Height - 2 * move;  

            Graphics g = pan.CreateGraphics();  

for (int i = 0; i <= len; i++)  

            {  

PointF py1 =new PointF(LenX * i / len + move, pan.Height - move - 4);  

PointF py2 =new PointF(LenX * i / len + move, pan.Height - move);  

string sy = ((maxX - minX) * i / len + minX).ToString();  

g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);  

g.DrawString(sy,new Font("宋体", 8f), Brushes.Black, new PointF(LenX * i / len + move, pan.Height - move / 1.1f));  

            }  

Pen pen =new Pen(Color.Black, 1);  

g.DrawString("X轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(pan.Width - move / 1.5f, pan.Height - move / 1.5f));  

        }  

        #endregion    

    }  

}  

相关文章

  • C#画坐标系

    usingSystem; usingSystem.Collections.Generic; usingSystem...

  • MATLAB基本2D作图(2)

    在同一个坐标系中画多个图 至少有三种方法可以在同一个坐标系中画多幅图: 最简单的办法。使用hold命令让绘图操作保...

  • 单目相机标定___一、原理

    原理:成像模型的坐标系为:世界坐标系 --> 相机坐标系 --> 图像坐标系 --> 像素坐标系 先说从相机坐标系...

  • WebGL知识点

    数学基础 坐标系:笛卡尔坐标系、极坐标等多坐标系:世界坐标系、物体坐标系、摄像机坐标系、惯性坐标系;向量、向量运算...

  • 2019-01-16echarts知识点

    echarts中的坐标系统分为,直角坐标系,极坐标系,雷达坐标系,地图坐标系

  • coreGraphics

    1. iOS 坐标系 NSView坐标系 : 左手坐标系 原点左上角UIView坐标系 : 左手坐标系 原点左...

  • 相机那些事(二)—— 单目成像原理与坐标变换

    一、单目相机成像原理 成像模型的坐标系为:世界坐标系 --> 相机坐标系 --> 图像坐标系 --> 像素坐标系 ...

  • 机床坐标系和工件坐标系和局部坐标系

    1:机床坐标系: 机床坐标系也称机械坐标系,它是CNC进行坐标计算的基准坐标系,是机床固有的坐标系,机床坐标系的原...

  • Android进阶笔记-6. 从源码看View体系(坐标,滑动,

    坐标系 Android中有两种坐标系,Android坐标系和视图坐标系 Android坐标系 定义:屏幕左上角顶点...

  • OpenGL下坐标系统解析

    左手坐标系和右手坐标系 OpenGL中的物体、世界、照相机坐标系都属于右手坐标系,而规范化设备坐标系使用左手坐标系...

网友评论

    本文标题:C#画坐标系

    本文链接:https://www.haomeiwen.com/subject/xliaxftx.html