コード例 #1
0
ファイル: MapHelper.cs プロジェクト: HillHouse/MilSym
        /// <summary>
        /// Generate a transform that transforms points in a space.
        /// </summary>
        /// <param name="fromPoints">
        /// The "from" points.
        /// </param>
        /// <param name="toPixels">
        /// The "to" points.
        /// </param>
        /// <returns>
        /// The 3x3 matrix that represents a transform from the points to the pixels.
        /// </returns>
        public static Matrix33 ComputeTransform(IList <Point> fromPoints, IList <Point> toPixels)
        {
            if (toPixels == null || fromPoints == null)
            {
                return(null);
            }

            var pixelMatrix = new Matrix33(toPixels);
            var pointMatrix = new Matrix33(fromPoints);

            return(pointMatrix.Inverse().Product(pixelMatrix));
        }
コード例 #2
0
ファイル: MapHelper.cs プロジェクト: HillHouse/MilSym
        /// <summary>
        /// Generate a transform that transforms points in pc space to locations in map space.
        /// </summary>
        /// <param name="fromPoints">
        /// The "from" points, typically values from a ResourceDictionary entry.
        /// </param>
        /// <param name="toAnchors">
        /// The "to" anchors, typically map locations.
        /// </param>
        /// <returns>
        /// The 3x3 matrix that represents a transform from the points to the anchors.
        /// </returns>
        public static Matrix33 ComputeTransform(IList <Point> fromPoints, IList <ILocation> toAnchors)
        {
            if (toAnchors == null || fromPoints == null)
            {
                return(null);
            }

            var anchorMatrix = new Matrix33(toAnchors);
            var pointMatrix  = new Matrix33(fromPoints);

            return(pointMatrix.Inverse().Product(anchorMatrix));
        }
コード例 #3
0
        /// <summary>
        /// Computes the product of two matrices.
        /// </summary>
        /// <param name="n">
        /// The matrix to multiply against - this x n.
        /// </param>
        /// <returns>
        /// The product of the two matrices.
        /// </returns>
        public Matrix33 Product(Matrix33 n)
        {
            // Don't bother with the _m entries since they're not being used.
            // Better not concatenate anything though.
            var p = new Matrix33
            {
                M11 = (this.M11 * n.M11) + (this.M12 * n.M21) + (this.m13 * n.M31),
                M12 = (this.M11 * n.M12) + (this.M12 * n.M22) + (this.m13 * n.M32),
                M21 = (this.M21 * n.M11) + (this.M22 * n.M21) + (this.m23 * n.M31),
                M22 = (this.M21 * n.M12) + (this.M22 * n.M22) + (this.m23 * n.M32),
                M31 = (this.M31 * n.M11) + (this.M32 * n.M21) + (this.m33 * n.M31),
                M32 = (this.M31 * n.M12) + (this.M32 * n.M22) + (this.m33 * n.M32)
            };

            return(p);
        }
コード例 #4
0
        /// <summary>
        /// Returns the inverse of the matrix.
        /// </summary>
        /// <returns>
        /// The inverse of the matrix.
        /// </returns>
        public Matrix33 Inverse()
        {
            double d   = this.Determinant();
            var    inv = new Matrix33
            {
                M11 = (this.M22 - this.M32) / d,
                M21 = (this.M31 - this.M21) / d,
                M31 = ((this.M21 * this.M32) - (this.M22 * this.M31)) / d,
                M12 = (this.M32 - this.M12) / d,
                M22 = (this.M11 - this.M31) / d,
                M32 = ((this.M31 * this.M12) - (this.M11 * this.M32)) / d,
                m13 = (this.M12 - this.M22) / d,
                m23 = (this.M21 - this.M11) / d,
                m33 = ((this.M11 * this.M22) - (this.M12 * this.M21)) / d
            };

            return(inv);
        }