/// <summary> /// Матрица вращения вокруг определённой оси. /// Учительский rot_axis /// </summary> private static double[,] AxleRotationMatrix(Point firstAxlePoint, Point secondAxlePoint, double angle) { /* Здесь происходят некие вещи, так называемые "тёмное программирование". * Этот участок кода оптимизирован учителем до упора, и структуризировать его особого смысла нету. * В связи с этим были изменены только названия переменных и методов. */ double a, b, c, d, length; double[,] m = new double[4, 4]; double[,] mr1 = new double[4, 4]; double[,] mr2 = new double[4, 4]; double[,] axleRotationMatrixResult = new double[4, 4]; a = secondAxlePoint.X - firstAxlePoint.X; b = secondAxlePoint.Y - firstAxlePoint.Y; c = secondAxlePoint.Z - firstAxlePoint.Z; length = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2) + Math.Pow(c, 2)); a = a / length; b = b / length; c = c / length; d = Math.Sqrt(Math.Pow(b, 2) + Math.Pow(c, 2)); if (d > 0.0000001) { double crd = (c / d); double brd = (b / d); { mr1 = MovementMatrix(firstAxlePoint.GetNegative()); m = NewMatrix(); m[1, 1] = crd; m[1, 2] = brd; //nondefault x rotation m[2, 1] = -brd; m[2, 2] = crd; mr2 = MultiplyMatrix(mr1, m); m = NewMatrix(); m[0, 0] = d; m[0, 2] = a; //nondefault y rotation m[2, 0] = -a; m[2, 2] = d; mr1 = MultiplyMatrix(mr2, m); m = DefaultZRotationMatrix(angle); //default z rotation mr2 = MultiplyMatrix(mr1, m); m = NewMatrix(); m[0, 0] = d; m[0, 2] = -a; //nondefault y rotation reverse m[2, 0] = a; m[2, 2] = d; mr1 = MultiplyMatrix(mr2, m); m = NewMatrix(); m[1, 1] = crd; m[1, 2] = -brd; // nondefault x rotation reverse m[2, 1] = brd; m[2, 2] = crd; mr2 = MultiplyMatrix(mr1, m); m = MovementMatrix(firstAxlePoint); axleRotationMatrixResult = MultiplyMatrix(mr2, m); } } else { mr1 = MovementMatrix(firstAxlePoint.GetNegative()); m = DefaultXRotationMatrix(angle); mr2 = MultiplyMatrix(mr1, m); m = MovementMatrix(firstAxlePoint); axleRotationMatrixResult = MultiplyMatrix(mr2, m); } return axleRotationMatrixResult; }
/// <summary> /// Матрица увеличения относительно точки. /// </summary> public static Matrix Scaling(double scale,Point scalePoint) { var centerBindingMatrix = MovementMatrix(scalePoint.GetNegative()); var scalingMatrix = DefaultScalingMatrix(scale); var positionReturningMatrix = MovementMatrix(scalePoint); scalingMatrix = MultiplyMatrix(centerBindingMatrix, scalingMatrix); scalingMatrix = MultiplyMatrix(scalingMatrix, positionReturningMatrix); var scalingMatrixResult = new Matrix() { type = MatrixType.Scaling, matrix = scalingMatrix }; return scalingMatrixResult; }