I am trying to develop a windows form based application in c#. The form has an image control and it has a scanned image of a floor plan. I get the x and y coordinates from the user of the real floor and I want to draw a small circle exactly on the same location on the image. This is showing the location of a user on the map.
The problem is that we can not equate the real world coordinates to screen pixels. So we need to get a formula for adjustment. Is there any formula for adjustment or we do it by trial and error. Also if we somehow adjust the conversion it will be based on the current screen resolution. Is there any formula for adjustment which caters for different screen resolution so that we can run the application on any screen size with any resolution.
By my understanding you have a problem with some lacking coordinate understanding. In the real world we think a coordinate plane as the lines X and Y forming 4 Quadrants.
On the computer you only work on the 1st quadrant and it's upside down meaning that origo (0,0) is your top left corner.
so to convert if you don't want to do it in your head
public int computerX(int realWorldX)
{
return realWorldX+(int)(ImageControl.Width/2);
}
public int computerY(int realWorldY)
{
int Convert = realWorldY+(int)(ImageControl.Height/2);
int Flip = ImageControl.Height - Convert;
return Flip;
}
when you placed realworld (1,1) you used some other cordinate in the program from the looks of it 25,25, you could just multiply so if you want realworld 2,2 then write 50,50 like this
public int computerX(int realWorldX)
{
return (realWorldX+(int)(ImageControl.Width/2))*yourXOffset;
}
public int computerY(int realWorldY)
{
int Convert = realWorldY+(int)(ImageControl.Height/2);
int Flip = ImageControl.Height - Convert;
return Flip*yourYOffset;
}