1

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

Community
  • 1
  • 1
Behzad74
  • 13
  • 3
  • I'm not really sure what you mean the differences are between mathematical and graphical coordinats? Opposed x and y? – einord Feb 28 '14 at 12:04
  • @einord see this pic to understand : http://s7.postimg.org/4jejypeor/Untitled.png – Behzad74 Feb 28 '14 at 12:20

2 Answers2

2

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 
musefan
  • 47,875
  • 21
  • 135
  • 185
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
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • Wow! thanks @lutzl it works well but just in 3 parts (TopRight , DownRight,DownLeft) but in the TOP LEFT x Should be positive but its negative you can see the program here : http://www.up2www.com/uploads/139359228131.zip – Behzad74 Feb 28 '14 at 13:00
  • Where do you get that requirement for the top-left corner from? In the second and third quadrant of the Cartesian coordinate system, the horizontal x coordinate is negative. – Lutz Lehmann Feb 28 '14 at 13:05
  • Oh yes you're right! , i was wrong, in the second Quadrant, x is negative and y is positive – Behzad74 Feb 28 '14 at 13:13
  • excuse me another question : How can i draw the mathematical coordinate axes in the program?? – Behzad74 Feb 28 '14 at 15:37
  • In plain vanilla winform just by drawing the corresponding lines in the paint event. Perhaps also adding some tick marks,... – Lutz Lehmann Feb 28 '14 at 15:48