예제 #1
0
        /// <summary>
        /// Creates a new keyed matrix from keyed vectors representing the rows of the new matrix
        /// </summary>
        /// <param name="axis1">The vector representing the first row</param>
        /// <param name="axis2">The vector representing the second row</param>
        /// <param name="axis3">The vector representing the third row</param>
        /// <returns>A matrix built from the vectors</returns>
        protected static KeyedSquareMatrix <DegreeOfFreedom> CreateFromRows(KeyedVector <DegreeOfFreedom> axis1, KeyedVector <DegreeOfFreedom> axis2, KeyedVector <DegreeOfFreedom> axis3)
        {
            ////TODO this should be devolved to the KeyedMatrix class
            Guard.AgainstBadArgument(
                "axis1",
                () => { return(axis1.Count != 3); },
                "All axes should be 3D, i.e. have 3 items");
            Guard.AgainstBadArgument(
                "axis2",
                () => { return(axis2.Count != 3); },
                "All axes should be 3D, i.e. have 3 items");
            Guard.AgainstBadArgument(
                "axis3",
                () => { return(axis3.Count != 3); },
                "All axes should be 3D, i.e. have 3 items");
            Guard.AgainstBadArgument(
                "axis1",
                () => { return(axis1.SumMagnitudes().IsApproximatelyEqualTo(0.0)); },
                string.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "Axis should not be zero: {0}",
                    axis1));
            Guard.AgainstBadArgument(
                "axis2",
                () => { return(axis2.SumMagnitudes().IsApproximatelyEqualTo(0.0)); },
                string.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "Axis should not be zero: {0}",
                    axis2));
            Guard.AgainstBadArgument(
                "axis3",
                () => { return(axis3.SumMagnitudes().IsApproximatelyEqualTo(0.0)); },
                string.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "Axis should not be zero: {0}",
                    axis3));

            KeyedVector <DegreeOfFreedom> axis1Norm = axis1.Normalize(2);
            KeyedVector <DegreeOfFreedom> axis2Norm = axis2.Normalize(2);
            KeyedVector <DegreeOfFreedom> axis3Norm = axis3.Normalize(2);

            IList <DegreeOfFreedom> dof = new List <DegreeOfFreedom>(3)
            {
                DegreeOfFreedom.X, DegreeOfFreedom.Y, DegreeOfFreedom.Z
            };

            KeyedSquareMatrix <DegreeOfFreedom> result = new KeyedSquareMatrix <DegreeOfFreedom>(dof);

            result.At(DegreeOfFreedom.X, DegreeOfFreedom.X, axis1Norm[DegreeOfFreedom.X]);
            result.At(DegreeOfFreedom.X, DegreeOfFreedom.Y, axis1Norm[DegreeOfFreedom.Y]);
            result.At(DegreeOfFreedom.X, DegreeOfFreedom.Z, axis1Norm[DegreeOfFreedom.Z]);
            result.At(DegreeOfFreedom.Y, DegreeOfFreedom.X, axis2Norm[DegreeOfFreedom.X]);
            result.At(DegreeOfFreedom.Y, DegreeOfFreedom.Y, axis2Norm[DegreeOfFreedom.Y]);
            result.At(DegreeOfFreedom.Y, DegreeOfFreedom.Z, axis2Norm[DegreeOfFreedom.Z]);
            result.At(DegreeOfFreedom.Z, DegreeOfFreedom.X, axis3Norm[DegreeOfFreedom.X]);
            result.At(DegreeOfFreedom.Z, DegreeOfFreedom.Y, axis3Norm[DegreeOfFreedom.Y]);
            result.At(DegreeOfFreedom.Z, DegreeOfFreedom.Z, axis3Norm[DegreeOfFreedom.Z]);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Creates a matrix which contains values from the requested sub-matrix
        /// </summary>
        /// <param name="rowsToInclude">A list of the keys of rows to include in the new matrix</param>
        /// <param name="columnsToInclude">A list of the keys of columns to include in the new matrix</param>
        /// <returns>A KeyedMatrix which contains values from the requested sub-matrix</returns>
        public KeyedSquareMatrix <TKey> SubMatrix(IList <TKey> keysToInclude)
        {
            KeyedSquareMatrix <TKey> subMatrix = new KeyedSquareMatrix <TKey>(keysToInclude);

            foreach (TKey rowKey in keysToInclude)        //rows
            {
                foreach (TKey columnKey in keysToInclude) //columns
                {
                    subMatrix.At(rowKey, columnKey, this.At(rowKey, columnKey));
                }
            }

            return(subMatrix);
        }