1

我想将图形 x,y 坐标 x,y 转换为数学坐标

(在这张图片中,您可以看到图形 x,y 和数学 x,y 之间的差异

情况示意图

e事件得到的图形x和图形y

         int graphicalx;
        int graphicaly;   
        graphicalx = e.X;
        graphicaly = e.Y;

他们在表单中通过两个标签显示只是应该在表单上移动鼠标

现在将图形 x,y 转换为数学 x,y 的公式是这样的:

图形 x = 数学 x + Alfa

图形 y = -数学 y + Beta

现在 Alfa 和 Beta 通过以下方式获得:

你得到你的电脑分辨率: 我的示例是:1600 * 800

阿尔法 = 1600 /2 = 800

贝塔 = 800/2 = 450

最后:阿尔法 = 800 贝塔 = 450

现在我的程序运行不好,问题出在哪里?

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        int graphicalx;
        int graphicaly;
        int mathematicalx;
        int mathematicaly;


        graphicalx = e.X;
        graphicaly = e.Y;


             if (graphicalx > 0)
        {
            graphicalx = graphicalx * -1; //if graphicalX was positive do it negative

        }
        if (graphicaly > 0)
        {
            graphicaly = graphicaly * -1; //if it graphicalY was positive do it negative

            }

        if (graphicalx < 0)
        {
            graphicalx = graphicalx * +1; // if graphicalX was negative do it positive
        }
        if (graphicaly < 0)
        {
            graphicaly = graphicaly * +1; // if graphicalY was negative do it positive
        }


       mathematicalx = graphicalx + 800; // the formula for obtain the mathematical x 
       mathematicaly = graphicaly * -1 + 450; // the formula for obtain the mathematical y 


        label1.Text = "X = " +mathematicalx.ToString();
        label3.Text = "Y = " + mathematicaly.ToString();

    }

表格 1 属性:

Windows 状态 = 最大化

FormBorderStyle = 无

4

2 回答 2

2

那么突出的第一个问题是您的反向方程实际上不是反向的,您需要减去这些值,而不是添加它们。尝试这个:

mathematicalx = graphicalx - 800; // the formula for obtain the mathematical x 
mathematicaly = (graphicaly - 450) * -1; // the formula for obtain the mathematical y 
于 2014-02-28T12:04:27.913 回答
0

To have some test cases according to the image and usual conventions, the corners and midpoint should satisfy the correspondence:

graphical     |   mathematical
-------------------------------
 (   0,   0)  |    (-800,  450)
 (   0, 900)  |    (-800, -450)
 (1600,   0)  |    ( 800,  450)
 (1600, 900)  |    ( 800, -450)
 ( 800, 450)  |    (   0,    0)

Which makes it

mathematical.x = graphical.x - 800
mathematical.y = 450 - graphical.y
于 2014-02-28T12:39:22.860 回答