Exemplo n.º 1
0
        /// <summary>
        /// Rotates a point around another around point with a given angle clockwise.
        /// </summary>
        /// <returns>The around point.</returns>
        /// <param name="angle">Angle.</param>
        /// <param name="center">Center.</param>
        /// <param name="point">Point.</param>
        public static PointF2D RotateAroundPoint(Radian angle, PointF2D center, PointF2D point)
        {
            double sin = System.Math.Sin (angle.Value);
            double cos = System.Math.Cos (angle.Value);

            double newX = center [0] + (cos * (point [0] - center[0]) + sin * (point [1] - center [1]));
            double newY = center [1] + (-sin * (point [0] - center[0]) + cos * (point [1] - center [1]));

            return new PointF2D (newX, newY);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rotates a set of points around another around point with a given angle clockwise.
        /// </summary>
        /// <returns>The around point.</returns>
        /// <param name="angle">Angle.</param>
        /// <param name="center">Center.</param>
        /// <param name="points">Points.</param>
        public static PointF2D[] RotateAroundPoint(Radian angle, PointF2D center, PointF2D[] points)
        {
            double sin = System.Math.Sin (angle.Value);
            double cos = System.Math.Cos (angle.Value);

            PointF2D[] rotated = new PointF2D[points.Length];
            for (int idx = 0; idx < points.Length; idx++) {
                double newX = center [0] + (cos * (points[idx] [0] - center[0]) + sin * (points[idx] [1] - center [1]));
                double newY = center [1] + (-sin * (points[idx] [0] - center[0]) + cos * (points[idx] [1] - center [1]));

                rotated[idx] = new PointF2D (newX, newY);
            }
            return rotated;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Rotates this view around it's center with a given angle and returns the modified version.
 /// </summary>
 /// <returns>The around center.</returns>
 /// <param name="angle">Angle.</param>
 public View2D RotateAroundCenter(Radian angle)
 {
     RectangleF2D rotated = this.Rectangle.RotateAroundCenter (angle);
     return new View2D (rotated, _invertX, _invertY);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Converts the given lambert coordinates to mercator coordinates.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public GeoCoordinate ConvertToWGS84(double x, double y)
        {
            double latitude;
            double longitude;

            double r = (System.Math.Sqrt(
                System.Math.Pow(x - _x_origin, 2.0) +
                System.Math.Pow((_r_0 - (y - _y_origin)), 2.0))
                );

            double t = System.Math.Pow((r / (_ellipsoid.SemiMajorAxis * _g)), 1.0 / _n);

            double phi = System.Math.Atan((x - _x_origin) /
                (_r_0 - (y - _y_origin)));

            longitude = ((phi / _n) + _longitude_origin_radians);

            latitude = (System.Math.PI / 2.0 - 2.0 * System.Math.Atan(t));

            double e = _ellipsoid.Eccentricity;

            double new_latitude = 0;
            while (new_latitude != latitude)
            { // iterate 100 times.
                new_latitude = latitude;
                latitude = (System.Math.PI / 2.0 - 2.0 *
                    System.Math.Atan(t *
                    System.Math.Pow(
                    ((1.0 - e * System.Math.Sin(latitude)) / (1.0 + e * System.Math.Sin(latitude))),
                    e / 2.0)));
            }

            Hayford1924Ellipsoid hayford = new Hayford1924Ellipsoid();

            double phi_72 = latitude; // phi = latitude!
            double lambda_72 = longitude; // lambda = longitude!
            double h_72 = 100;

            double a_72 = hayford.SemiMajorAxis;
            double e_72 = hayford.Eccentricity;
            double es_72 = e_72 * e_72;
            double sin_phi_72 = System.Math.Sin(phi_72);
            double cos_phi_72 = System.Math.Cos(phi_72);
            double sin_lambda_72 = System.Math.Sin(lambda_72);
            double cos_lambda_72 = System.Math.Cos(lambda_72);
            double v_72 = a_72 / System.Math.Sqrt(1 - (es_72 * sin_phi_72 * sin_phi_72));

            double X_72 = (v_72 + h_72) * cos_phi_72 * cos_lambda_72;
            double Y_72 = (v_72 + h_72) * cos_phi_72 * sin_lambda_72;
            double Z_72 = ((1 - es_72) * v_72 + h_72) * sin_phi_72;

            // ALL OK

            //X_72 = X_72 * (1 / 1.0000012747);
            //Y_72 = Y_72 * (1 / 1.0000012747);
            //Z_72 = Z_72 * (1 / 1.0000012747);

            // translations.
            double x_trans = 106.868628;
            double y_trans = 52.297783;
            double z_trans = 103.723893;

            double X_89 = X_72 - x_trans;
            double Y_89 = Y_72 + y_trans;
            double Z_89 = Z_72 - z_trans;

            // rotations.
            double x_angle = ((Radian)new Degree(0.336570 / 3600)).Value;
            double sin_x_angle = System.Math.Sin(x_angle);
            double cos_x_angle = System.Math.Cos(x_angle);
            double y_angle = ((Radian)new Degree(-0.456955 / 3600)).Value;
            double sin_y_angle = System.Math.Sin(y_angle);
            double cos_y_angle = System.Math.Cos(y_angle);
            double z_angle = ((Radian)new Degree(1.842183 / 3600)).Value;
            double sin_z_angle = System.Math.Sin(z_angle);
            double cos_z_angle = System.Math.Cos(z_angle);
            // rotate around x.
            //X_89 = X_89;
            Y_89 = Y_89 * cos_x_angle - Z_89 * sin_x_angle;
            Z_89 = Y_89 * sin_x_angle + Z_89 * cos_x_angle;
            // rotate around y.
            X_89 = X_89 * cos_y_angle + Z_89 * sin_y_angle;
            //Y_89 = Y_89;
            Z_89 = X_89 * (-sin_y_angle) + Z_89 * cos_y_angle;
            // rotate around Z.
            X_89 = X_89 * cos_z_angle - Y_89 * sin_z_angle;
            Y_89 = X_89 * sin_z_angle + Y_89 * cos_z_angle;
            //Z_89 = Z_89;

            Wgs1984Ellipsoid wgs1984 = new Wgs1984Ellipsoid();

            e = wgs1984.Eccentricity;
            double es = e * e;
            double ps = X_89 * X_89 + Y_89 * Y_89;
            double p = System.Math.Sqrt(ps);

            r = System.Math.Sqrt(ps + Z_89 * Z_89);

            double f = wgs1984.Flattening;
            double a = wgs1984.SemiMajorAxis;

            double u = System.Math.Atan((Z_89 / p) * ((1 - f) + (es * a / r)));
            double lambda = System.Math.Atan(Y_89 / X_89);
            phi = System.Math.Atan((Z_89 * (1 - f) + (es * a * System.Math.Pow(System.Math.Sin(u), 3)))
                /
               ((1 - f) * (p - (es * a * System.Math.Pow(System.Math.Cos(u), 3)))));

            Degree longitude_84 = new Radian(lambda);
            Degree latitude_84 = new Radian(phi);

            return new GeoCoordinate(latitude_84.Value, longitude_84.Value);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new angle in radians.
 /// </summary>
 /// <param name="value"></param>
 public Radian(double value)
     : base(Radian.Normalize(value))
 {
 }