Exemple #1
0
        /// <summary>
        /// Writes workplane to a MATRIX file.
        /// </summary>
        /// <param name="matrixFile">The file path to the '.matrix' file.</param>
        public void WriteToMatrix(File matrixFile)
        {
            matrixFile.Delete();

            // The expected format of the transformation matrix is the following:
            //xAxis.i|yAxis.i|zAxis.i|x
            //xAxis.j|yAxis.j|zAxis.j|y
            //xAxis.k|yAxis.k|zAxis.k|z
            //0|0|0|1

            // The 1st column is the new x vector relative to World
            // The 2nd column is the new y vector relative to World
            // The 3rd column is the new z vector relative to World
            // The 4th column is the new origin position relative to World

            string firstTranformationMatrixLine  = $"{XAxis.I}|{YAxis.I}|{ZAxis.I}|{Origin.X}";
            string secondTranformationMatrixLine = $"{XAxis.J}|{YAxis.J}|{ZAxis.J}|{Origin.Y}";
            string thirdTranformationMatrixLine  = $"{XAxis.K}|{YAxis.K}|{ZAxis.K}|{Origin.Z}";
            string fourthTranformationMatrixLine = "0|0|0|1";

            var lines = new List <string>(6);

            lines.Add(firstTranformationMatrixLine);
            lines.Add(secondTranformationMatrixLine);
            lines.Add(thirdTranformationMatrixLine);
            lines.Add(fourthTranformationMatrixLine);

            matrixFile.WriteTextLines(lines);
        }
Exemple #2
0
        /// <summary>
        /// Writes the transformation matrix to a TRX file.
        /// </summary>
        /// <param name="trxFile">The TRX file to write.</param>
        /// <param name="rotationMatrix">The rotation matrix.</param>
        /// <param name="translation">The translation matrix.</param>
        private void WriteRotationMatrixAndTranslationToTrxFile(
            File trxFile,
            double[,] rotationMatrix,
            double[] translation)
        {
            trxFile.Delete();

            Degree[] rotations     = Angles.GetRotationsFromMatrixXYZ(rotationMatrix);
            string   xRotationLine = "ROT_X: " +
                                     (rotations[2].Value >= 0.0
                                       ? rotations[2].Value.ToString("+0.000")
                                       : rotations[2].Value.ToString("0.000"));
            string yRotationLine = "ROT_Y: " +
                                   (rotations[1].Value >= 0.0
                                       ? rotations[1].Value.ToString("+0.000")
                                       : rotations[1].Value.ToString("0.000"));
            string zRotationLine = "ROT_Z: " +
                                   (rotations[0].Value >= 0.0
                                       ? rotations[0].Value.ToString("+0.000")
                                       : rotations[0].Value.ToString("0.000"));
            string xTranslationLine = "SHIFT_X: " +
                                      (translation[0] >= 0.0
                                          ? translation[0].ToString("+0.000")
                                          : translation[0].ToString("0.000"));
            string yTranslationLine = "SHIFT_Y: " +
                                      (translation[1] >= 0.0
                                          ? translation[1].ToString("+0.000")
                                          : translation[1].ToString("0.000"));
            string zTranslationLine = "SHIFT_Z: " +
                                      (translation[0] >= 0.0
                                          ? translation[2].ToString("+0.000")
                                          : translation[2].ToString("0.000"));

            var lines = new List <string>(6);

            lines.Add(xRotationLine);
            lines.Add(yRotationLine);
            lines.Add(zRotationLine);
            lines.Add(xTranslationLine);
            lines.Add(yTranslationLine);
            lines.Add(zTranslationLine);

            trxFile.WriteTextLines(lines);
        }