Question

i want to convert graphical x,y coordinates x,y to mathematical coordinated

( in this picture you see the Differences between graphical x,y and mathematical x,y

sketch of the situation

the graphical x and graphical y obtain by e event

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

and they showed by two label in the form just should move the mouse on the form

Now the formula for convert graphicalx,y to mathematical x,y is this :

Graphical x = mathematical x + Alfa

Graphical y = - mathematical y + Beta

Now the Alfa and Beta obtain by this :

you get the your computer resolution : for sample mine is : 1600 * 800

alfa = 1600 /2 = 800

beta = 800/2 = 450

At last : alfa = 800 beta = 450

and now my program don`t works well , where is the problem?

    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();

    }

Form 1 Properties :

Windows state = Maximized

FormBorderStyle = None

Was it helpful?

Solution 2

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

OTHER TIPS

Well the first problem that stands out is your reverse equations are not actual a reverse, you need to subtract the values, not add them. Try this:

mathematicalx = graphicalx - 800; // the formula for obtain the mathematical x 
mathematicaly = (graphicaly - 450) * -1; // the formula for obtain the mathematical y 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top