当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Rotate方法代码示例

本文整理汇总了C#中Matrix.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Rotate方法的具体用法?C# Matrix.Rotate怎么用?C# Matrix.Rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix的用法示例。


在下文中一共展示了Matrix.Rotate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RotateAndFindNewDimensions

    private static PointF RotateAndFindNewDimensions(PointF point, float angle) {
        using (Matrix matrix = new Matrix()) {
            PointF[] points = new PointF[] {
                    new PointF(0f, 0f),
                    new PointF(0f, point.Y),
                    new PointF(point.X, 0f),
                    new PointF(point.X, point.Y)
                };

            matrix.Rotate(angle);
            matrix.TransformPoints(points);
            float minX = points[0].X;
            float maxX = minX;
            float minY = points[0].Y;
            float maxY = minY;
            for (int i = 1; i < 4; i++) {
                minX = Math.Min(minX, points[i].X);
                maxX = Math.Max(maxX, points[i].X);
                minY = Math.Min(minY, points[i].Y);
                maxY = Math.Max(maxY, points[i].Y);
            }

            return new PointF(maxX - minX, maxY - minY);
        }
    }
开发者ID:javidondeesta,项目名称:tech-talks,代码行数:25,代码来源:MultiThumbnailGenerator.cs

示例2: Run

        public static void Run()
        {
            // ExStart:AddDiagonalWatermarkToImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing JPG image
            using (Image image = Image.Load(dataDir + "SampleTiff1.tiff"))
            {
                // Declare a String object with Watermark Text
                string theString = "45 Degree Rotated Text";

                // Create and initialize an instance of Graphics class and Initialize an object of SizeF to store image Size
                Graphics graphics = new Graphics(image);
                SizeF sz = graphics.Image.Size;

                // Creates an instance of Font, initialize it with Font Face, Size and Style
                Font font = new Font("Times New Roman", 20, FontStyle.Bold);

                // Create an instance of SolidBrush and set its various properties
                SolidBrush brush = new SolidBrush();
                brush.Color = Color.Red;
                brush.Opacity = 0;

                // Initialize an object of StringFormat class and set its various properties
                StringFormat format = new StringFormat();
                format.Alignment = StringAlignment.Center;
                format.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

                // Create an object of Matrix class for transformation
                Matrix matrix = new Matrix();

                // First a translation then a rotation                
                matrix.Translate(sz.Width / 2, sz.Height / 2);             
                matrix.Rotate(-45.0f);

                // Set the Transformation through Matrix
                graphics.Transform = matrix;

                // Draw the string on Image Save output to disk
                graphics.DrawString(theString, font, brush, 0, 0, format);
                image.Save(dataDir + "AddDiagonalWatermarkToImage_out.jpg");
            }
            // ExStart:AddDiagonalWatermarkToImage
        }
开发者ID:aspose-imaging,项目名称:Aspose.Imaging-for-.NET,代码行数:45,代码来源:AddDiagonalWatermarkToImage.cs

示例3: SetSteeringAngle

    public void SetSteeringAngle(float newAngle)
    {
        Matrix mat = new Matrix();
        PointF[] vectors = new PointF[2];

        //foward vector
        vectors[0].X = 0;
        vectors[0].Y = 1;
        //side vector
        vectors[1].X = -1;
        vectors[1].Y = 0;

        mat.Rotate(newAngle / (float)Math.PI * 180.0f);
        mat.TransformVectors(vectors);

        m_forwardAxis = new Vector(vectors[0].X, vectors[0].Y);
        m_sideAxis = new Vector(vectors[1].X, vectors[1].Y);
    }
开发者ID:zenmumbler,项目名称:GranZero,代码行数:18,代码来源:Wheel.cs

示例4: WorldTransform

        //	sets up a translation matrix for the sweeper according to its
        public void WorldTransform(ref List<Point> sweeper)
        {
            //create the world transformation matrix
            var transform = new Matrix();

            //scale
            transform.Scale(Scale, Scale);

            //rotate
            transform.Rotate(Rotation);

            //and translate
            transform.Translate(Position.X, Position.Y);

            //now transform the ships vertices
            transform.TransformPoints(ref sweeper);
        }
开发者ID:Oxymoron290,项目名称:CSharp-AI-Mine-Sweepers,代码行数:18,代码来源:MineSweeper.cs

示例5: CreateRectangleSymbol

        // Rectangle symbols may be translated into multiple symbols (if there is a grid).
        Symbol[] CreateRectangleSymbol(OcadObject obj, LineSymDef symdef, RectangleInfo rectinfo)
        {
            List<Symbol> symlist = new List<Symbol>();  // list of symbols we're creating.

            if (symdef == null)
                throw new OcadFileFormatException("Object has unknown or inconsistent symbol type {0}", obj.Sym);

            if (obj.coords == null || obj.coords.Length < 2)
                return null;

            // Create the main rectangle symbol.
            // Determine size of the rectangle, and matrix needed to transform points to their correct location.
            PointF[] pts = {PointFromOcadCoord(obj.coords[0]), PointFromOcadCoord(obj.coords[1]), PointFromOcadCoord(obj.coords[2]), PointFromOcadCoord(obj.coords[3])};
            SizeF size = new SizeF(Util.DistanceF(pts[0], pts[1]), Util.DistanceF(pts[0], pts[3]));
            float angle = Util.Angle(pts[0], pts[1]);
            Matrix matrix = new Matrix();
            matrix.Translate(pts[0].X, pts[0].Y);
            matrix.Rotate(angle);

            SymPath path;
            PointKind[] kinds;
            PointF[] pathpts;
            if (rectinfo.cornerRadius == 0) {
                kinds = new PointKind[] {PointKind.Corner, PointKind.Corner, PointKind.Corner, PointKind.Corner, PointKind.Corner};
                pathpts = new PointF[] { new PointF(0,0), new PointF(0, size.Height), new PointF(size.Width, size.Height),
                                           new PointF(size.Width, 0), new PointF(0,0)};
            }
            else {
                kinds = new PointKind[] {PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
                                            PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
                                            PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
                                            PointKind.Normal, PointKind.Normal, PointKind.BezierControl, PointKind.BezierControl,
                                            PointKind.Normal};
                pathpts = new PointF[] { new PointF(rectinfo.cornerRadius, 0),
                                           new PointF(size.Width - rectinfo.cornerRadius, 0),
                                           new PointF(size.Width - (1-Util.kappa) * rectinfo.cornerRadius, 0),
                                           new PointF(size.Width, (1-Util.kappa) * rectinfo.cornerRadius),
                                           new PointF(size.Width, rectinfo.cornerRadius),
                                           new PointF(size.Width, size.Height - rectinfo.cornerRadius),
                                           new PointF(size.Width, size.Height - (1-Util.kappa) * rectinfo.cornerRadius),
                                           new PointF(size.Width - (1-Util.kappa) * rectinfo.cornerRadius, size.Height),
                                           new PointF(size.Width - rectinfo.cornerRadius, size.Height),
                                           new PointF(rectinfo.cornerRadius, size.Height),
                                           new PointF((1-Util.kappa) * rectinfo.cornerRadius, size.Height),
                                           new PointF(0, size.Height - (1-Util.kappa) * rectinfo.cornerRadius),
                                           new PointF(0, size.Height - rectinfo.cornerRadius),
                                           new PointF(0, rectinfo.cornerRadius),
                                           new PointF(0, (1-Util.kappa) * rectinfo.cornerRadius),
                                           new PointF((1-Util.kappa) * rectinfo.cornerRadius, 0),
                                           new PointF(rectinfo.cornerRadius, 0)};
            }

            pathpts = GraphicsUtil.TransformPoints(pathpts, matrix);
            for (int i = 0; i < pathpts.Length; ++i)
                pathpts[i] = new PointF((float) Math.Round(pathpts[i].X, 2), (float) Math.Round(pathpts[i].Y, 2));   // round to 2 decimals, so round trip to OCAD without change.
            path = new SymPath(pathpts, kinds);
            symlist.Add(new LineSymbol(symdef, path));

            if (rectinfo.grid) {
                if (size.Width > 0 && size.Height > 0) {
                    int cxCells = (int) Math.Round(size.Width / rectinfo.cellWidth);
                    if (cxCells < 1)
                        cxCells = 1;
                    int cyCells = (int) Math.Round(size.Height / rectinfo.cellHeight);
                    if (cyCells < 1)
                        cyCells = 1;

                    float width = size.Width / cxCells;
                    float height = size.Height / cyCells;

                    CreateGridLines(size, matrix, cxCells, cyCells, width, height, rectinfo.gridLines, symlist);
                    CreateGridText(size, matrix, angle, cxCells, cyCells, width, height, rectinfo, symlist);
                }
            }

            return symlist.ToArray();
        }
开发者ID:jonc,项目名称:carto,代码行数:78,代码来源:OcadImport.cs

示例6: RelativeToWorld

    //take a relative vector and make it a world vector
    public Vector RelativeToWorld(Vector relative)
    {
        Matrix mat = new Matrix();
        PointF[] vectors = new PointF[1];

        vectors[0].X = relative.X;
        vectors[0].Y = relative.Y;

        mat.Rotate(m_angle / (float)Math.PI * 180.0f);
        mat.TransformVectors(vectors);

        return new Vector(vectors[0].X, vectors[0].Y);
    }
开发者ID:zenmumbler,项目名称:GranZero,代码行数:14,代码来源:RigidBody.cs

示例7: WorldToRelative

    //take a world vector and make it a relative vector
    public Vector WorldToRelative(Vector world)
    {
        Matrix mat = new Matrix();
        PointF[] vectors = new PointF[1];

        vectors[0].X = world.X;
        vectors[0].Y = world.Y;

        mat.Rotate(-m_angle / (float)Math.PI * 180.0f);
        mat.TransformVectors(vectors);

        return new Vector(vectors[0].X, vectors[0].Y);
    }
开发者ID:zenmumbler,项目名称:GranZero,代码行数:14,代码来源:RigidBody.cs

示例8: IsFit

    public bool IsFit(Point[] points)
    {
        // Note: rigorously calculating distance(point,ellipse) is very hard...
        // overlay the regions and compare the areas, for now.
        using (GraphicsPath polygp = new GraphicsPath())
        using (GraphicsPath elligp = new GraphicsPath())
        using (Matrix m = new Matrix())
        {
            // Set up gp for stroke.
            polygp.AddPolygon(points);

            // Set up gp for ellipse.
            elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);

            m.Translate((float)cx,(float)cy);
            m.Rotate((float)th);
            elligp.Transform(m);

            // Prepare regions for area-calculation.
            using (Region xor = new Region(elligp))
            using (Region isc = new Region(elligp))
            {
                xor.Xor(polygp);
                isc.Intersect(polygp);

                float badarea = Geometry.CalculateArea(xor);
                float iscarea = Geometry.CalculateArea(isc);
                float ratio = iscarea/badarea;

                //heuristic: 10.0 seems about right.
                return (ratio > 10f);
            }
        }
    }
开发者ID:pichiliani,项目名称:CoPhysicsSimulator,代码行数:34,代码来源:Ellipse.cs

示例9: Test

    /// <summary>
    /// Some test code to check that there are no typing errors in the formulars.
    /// </summary>
    public static void Test()
    {
      XMatrix xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
      Matrix  m1 = new Matrix(23, -35, 837, 332, -3, 12);
      DumpMatrix(xm1, m1);
      XMatrix xm2 = new XMatrix(12, 235, 245, 42, 33, -56);
      Matrix  m2 = xm2.ToMatrix();
      DumpMatrix(xm2, m2);

//      xm1.Multiply(xm2, XMatrixOrder.Prepend);
//      m1.Multiply(m2, MatrixOrder.Append);
      xm1.Multiply(xm2, XMatrixOrder.Append);
      m1.Multiply(m2, MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Translate(-243, 342, XMatrixOrder.Append);
      m1.Translate(-243, 342, MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Scale(-5.66, 7.87);
      m1.Scale(-5.66f, 7.87f);
//      xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
//      m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);


      xm1.Rotate(135, XMatrixOrder.Append);
      m1.Rotate(135, MatrixOrder.Append);
      //      xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
      //      m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);

      xm1.RotateAt(177, new XPoint(-3456, 654), XMatrixOrder.Append);
      m1.RotateAt(177, new PointF(-3456, 654), MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Shear(0.76, -0.87, XMatrixOrder.Prepend);
      m1.Shear(0.76f, -0.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);

      xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
      m1 = new Matrix(23, -35, 837, 332, -3, 12);

      XPoint[] xpoints = new XPoint[3]{new XPoint(23, 10), new XPoint(-27, 120), new XPoint(-87, -55)};
      PointF[] points = new PointF[3]{new PointF(23, 10), new PointF(-27, 120), new PointF(-87, -55)};

      xm1.TransformPoints(xpoints);
      m1.TransformPoints(points);

      xm1.Invert();
      m1.Invert();
      DumpMatrix(xm1, m1);

    }
开发者ID:BackupTheBerlios,项目名称:zp7-svn,代码行数:57,代码来源:XMatrix.cs

示例10: UpdateGP

    protected internal override void UpdateGP()
    {
        // We keep the gp updated as we go; if it's already initialized, return.
        if (gp != null) return;
        else gp = new GraphicsPath();

        // Establish the elliptical shape.
        gp.AddEllipse(-MajorAxis,-MinorAxis,MajorAxis*2,MinorAxis*2);

        using (Matrix m = new Matrix())
        {
            m.Translate(CenterPoint.X,CenterPoint.Y);
            m.Rotate(Orientation);
            gp.Transform(m);
        }

        // Reset the displacement matrix and clear associated caches.
        if (displacement == null)
            displacement = new Matrix();
        else
            displacement.Reset();

        if (rgncache != null) rgncache.Dispose();
        rgncache = null;
    }
开发者ID:pichiliani,项目名称:CoPhysicsSimulator,代码行数:25,代码来源:MagicObjects.cs


注:本文中的Matrix.Rotate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。