Mapping Real World coordinates to a Panel
-
Friday, August 10, 2012 9:52 PMI haven't done this in so long I've forgotten how to do it.
I'm trying to map real-world coordinates to a Panel.
The real-world coordinates are oriented such that positive vertical values go up (negative down), positive horizontal values go right (negative left), much like any standard map.
The Panelhas its origin at the upper left-hand corner, with positive vertical pixel values going DOWN (the OPPOSITE of the real world values), and positive horizontal pixel values going right (the SAME as the real world values).
I know the size of the bitmap (BitmapWidth and BitmapHeight). And I know the real world values for the sides of the real world area (RealWordlLeft, RealWordlRight, RealWordlTop, RealWordlBottom).
Now, given any particular real world value (e.g. X = 39.27, Y = 401.2) how do I calculate the corresponding pixel coordinates for the Panel?
All Replies
-
Saturday, August 11, 2012 1:58 AM
There is a good discussion of this at Bob Powell's site (http://www.bobpowell.net/faqmain.htm). In particular, look for the sections discussing transformations.
--
Mike- Proposed As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Tuesday, August 14, 2012 3:34 AM
- Marked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Monday, August 20, 2012 8:12 AM
-
Monday, August 20, 2012 7:26 PM
Here's what I finally came up with. I hope the various variables and constants are obvious from their names.
static public bool RealWorldEndPositionFromStartingPosition_Direction_Distance( double RealWorldStartingX, double RealWorldStartingY, double DirectionNorthernOrientation, double Distance, ref double RealWorldEndingX, ref double RealWorldEndingY ) { // Given a starting point in real-world rectangular coordinates, a Direction in NORTHERN orientation, and a Distance // this returns the End point in rectangular coordinates. // Think of it as a line with a starting point, direction and length and we want to calculate // the position of the end point. double DirectionPolarOrientation = DegreesPolarFromDegreesNorthern(DirectionNorthernOrientation); double DirectionPolarOrientationInRadians = RadiansFromDegrees(DirectionPolarOrientation); RealWorldEndingX = (int)(Distance * Math.Cos(DirectionPolarOrientationInRadians)) + RealWorldStartingX; RealWorldEndingY = (int)((Distance * Math.Sin(DirectionPolarOrientationInRadians)) + RealWorldStartingY); // *-1; // We multiply by -1 because for the graphics in the panel it uses positive as going downwards // We want it going upwards. return true; }- Marked As Answer by Roger C Garrett in Hawaii Monday, August 20, 2012 7:27 PM

