예제 #1
0
        public Matrix GeneratePolygon()
        {
            if (mShapeType == EShapeType.Polygon)
            {
                Matrix mat = new Matrix(2);
                for (int i = 0; i < mSides; i++)
                {
                    double x = mRadius * Math.Cos((2 * Math.PI / mSides) * i);
                    double y = mRadius * Math.Sin((2 * Math.PI / mSides) * i);
                    mat.AddRow(new Double[] { x, y });
                }


                if (mIsBeveled)
                {
                    Matrix bevelmat = (Matrix)mat.Clone();
                    RotationalTransformation rot = new RotationalTransformation()
                    {
                        Matrix = bevelmat
                    };
                    rot.Matrix = bevelmat;
                    rot.RotateDegreesAroundOrigin(mBevelOffset);
                    mat.Interleave(bevelmat, false);
                    rot.Matrix = mat;
                    rot.RotateDegreesAroundOrigin(-mBevelOffset / 2);
                }


                return(mat);
            }
            else
            {
                Matrix outerMat = new Matrix(2);
                for (int i = 0; i < mSides; i++)
                {
                    double x = mRadius * Math.Cos((2 * Math.PI / mSides) * i);
                    double y = mRadius * Math.Sin((2 * Math.PI / mSides) * i);
                    outerMat.AddRow(new Double[] { x, y });
                }

                Matrix innerMat = (Matrix)outerMat.Clone();
                innerMat.Multiply(mInnerRadius / mRadius); // Will work because centered about origin
                RotationalTransformation rot = new RotationalTransformation()
                {
                    Matrix = innerMat
                };
                rot.RotateRadiansAroundOrigin(Math.PI / mSides); //Circle is 2PI radians
                if (mIsAngularlyOffset)
                {
                    rot.RotateDegreesAroundOrigin(mAngularOffset);
                }
                outerMat.Interleave(innerMat, false);

                if (mIsBeveled)
                {
                    Matrix bevelmat = (Matrix)outerMat.Clone();
                    rot.Matrix = bevelmat;
                    rot.RotateDegreesAroundOrigin(mBevelOffset);
                    outerMat.Interleave(bevelmat, false);
                    rot.Matrix = outerMat;
                    rot.RotateDegreesAroundOrigin(-mBevelOffset / 2);//Remove appearance of rotation
                }

                return(outerMat);
            }
        }