PurplePen.CoordinateMapper.GetRealWorld C# (CSharp) Method

GetRealWorld() public method

public GetRealWorld ( PointF paperCoord, double &realX, double &realY ) : bool
paperCoord System.Drawing.PointF
realX double
realY double
return bool
        public bool GetRealWorld(PointF paperCoord, out double realX, out double realY)
        {
            if (hasRealWorldCoords) {
                double x = paperCoord.X, y = paperCoord.Y;
                x *= (mapScale / 1000.0); y *= (mapScale / 1000.0);
                double ang = (-realWorldCoords.RealWorldAngle * Math.PI) / 180.0;
                realX = x * Math.Cos(ang) - y * Math.Sin(ang);
                realY = x * Math.Sin(ang) + y * Math.Cos(ang);
                realX += realWorldCoords.RealWorldOffsetX;
                realY += realWorldCoords.RealWorldOffsetY;

                realX -= realWorldCoords.RealWorldLocalOffsetX;
                realY -= realWorldCoords.RealWorldLocalOffsetY;
                return true;
            }
            else {
                realX = realY = 0;
                return false;
            }
        }

Usage Example

Beispiel #1
0
        // Create a world file using the given coordinate mapper.
        // See https://en.wikipedia.org/wiki/World_file
        private void CreateWorldFile(string worldFileName, RectangleF rect, float bitmapWidth, float bitmapHeight, CoordinateMapper mapperForWorldFile)
        {
            double a, b, c, d, e, f;
            Matrix transform = Geometry.CreateInvertedRectangleTransform(new RectangleF(0, 0, bitmapWidth, bitmapHeight), rect);

            PointF[] transformedPoints = Geometry.TransformPoints(new PointF[] { new PointF(0, 0), new PointF(1, 0), new PointF(0, 1) }, transform);
            double[] realX             = new double[transformedPoints.Length];
            double[] realY             = new double[transformedPoints.Length];
            for (int i = 0; i < transformedPoints.Length; ++i)
            {
                mapperForWorldFile.GetRealWorld(transformedPoints[i], out realX[i], out realY[i]);
            }

            c = realX[0];
            f = realY[0];
            a = realX[1] - c;
            d = realY[1] - f;
            b = realX[2] - c;
            e = realY[2] - f;

            using (TextWriter writer = new StreamWriter(worldFileName)) {
                writer.WriteLine(a.ToString("F10", CultureInfo.InvariantCulture));
                writer.WriteLine(d.ToString("F10", CultureInfo.InvariantCulture));
                writer.WriteLine(b.ToString("F10", CultureInfo.InvariantCulture));
                writer.WriteLine(e.ToString("F10", CultureInfo.InvariantCulture));
                writer.WriteLine(c.ToString("F5", CultureInfo.InvariantCulture));
                writer.WriteLine(f.ToString("F5", CultureInfo.InvariantCulture));
            }
        }