예제 #1
0
        /// <summary>
        /// Rotates about the origin. Returns a new matrix with the result.
        /// </summary>
        /// <param name="degrees">The degrees to rotate.</param>
        /// <param name="clockwise">If False, then + degrees rotates counter clockwise.
        /// If True, then + degrees rotates clockwise. Of course, if the sign of the degrees
        /// is -, then the rotation will be opposite whatever the + direction is.</param>
        public Transform2D Rotate(decimal degrees, bool clockwise = false)
        {
            var r = new Transform2D();

            var theta = DecimalEx.ToRad(degrees);

            if (clockwise)
            {
                theta *= -1;
            }

            //      0     1    2
            // 0   cos  -sin   0
            // 1   sin   cos   0
            // 2    0     0    1

            r[0, 0] = DecimalEx.Cos(theta);
            r[0, 1] = -DecimalEx.Sin(theta);
            r[1, 0] = DecimalEx.Sin(theta);
            r[1, 1] = DecimalEx.Cos(theta);

            return(r.Multiply(this));
        }