c# making a coordinate system for a picture

Discussion in 'Software' started by mastermosley, May 17, 2010.

  1. mastermosley

    mastermosley Sergeant

    Okay, I have an image in a picture box locating in a panel so it has a scroll bar and its anchored so it maximizes with the form. The image is a map and im trying to make a coordinate system for it, but I have no idea where to start.

    The system includes: Degrees, Minutes for North and South, Degrees, Minutes for West and East. The start location (Origin) is in a random location on the image where it would be: 0d 0m North 0d 0m West

    I cant really explain but when you move your mouse that tiny little bit that moves it over just that tiny little bit, to the next pixel maybe I dont no, will increment the minutes. After 60 minutes it will restart to 0 and the degrees will go up one.

    Where do I start? I can make a certain part of the image the origin and make a formula so it calculates the cordinates on any area of the picture??
     
  2. mastermosley

    mastermosley Sergeant

    Code:
    Point LocalMousePosition = new Point();
                LocalMousePosition = pictureBox1.PointToClient(Cursor.Position);
                toolStripStatusLabel1.Text = "X=" + LocalMousePosition.X + "," + "Y=" + LocalMousePosition.Y;
    
    This sets it up so that it tells me the location from the top left corner of the map. Is there anyway I can set the origin from the top left corner to a specific coordinate like. x=785 y=1994.
     
  3. PC-XT

    PC-XT Master Sergeant

    Subtract the numbers from the coords:
    Code:
    toolStripStatusLabel1.Text = "X=" + (LocalMousePosition.X-785) + "," + "Y=" + (LocalMousePosition.Y-1994);
    This will give (0,0) for (785,1994)
    I guess you know how to get degrees, minutes from that:
    Use modulus to find the minutes: min = Math.Abs(x) % 60;
    Use division and Math.Floor to find the degrees: deg = Math.Floor(x / 60);

    I used Math.Abs on the minutes, because you probably don't want to repeat the sign that will already be in the degrees.
     
  4. mastermosley

    mastermosley Sergeant

    Ya thanks, that worked like a charm, only thing now is I'm having a problem drawing a horizontal and vertical line on the map. Say someone selects 630x 450y i want both lines to go through thoughs points??
     
  5. PC-XT

    PC-XT Master Sergeant

    Is that map coords, or mouse coords?
    If it is map coords, you will need to add the bias back (785 to x, 1994 to y in your example) before the following will work right:

    To draw the vertical line, use
    DrawLine(blackPen, x, y-h, x, y+h);
    where h is half the line size: h=lineLength/2;
    For the horizontal one,
    DrawLine(blackPen, x-h, y, x+h, y);
    should work.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds