Mapping Real World coordinates to a Panel

# Mapping Real World coordinates to a Panel

• Friday, August 10, 2012 9:52 PM

I 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
• 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);