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


C# Matrix.TransformVectors方法代码示例

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


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

示例1: DrawGraph

        // Draw the graph.
        private void DrawGraph(Graphics gr)
        {
            // Map to turn right-side up and center at the origin.
            const float wxmin = -10;
            const float wymin = -10;
            const float wxmax = 10;
            const float wymax = 10;
            RectangleF rect = new RectangleF(wxmin, wymin, wxmax - wxmin, wymax - wymin);
            PointF[] pts =
            {
                new PointF(0, graphPictureBox.ClientSize.Height),
                new PointF(graphPictureBox.ClientSize.Width, graphPictureBox.ClientSize.Height),
                new PointF(0, 0),
            };
            Matrix transform = new Matrix(rect, pts);
            gr.Transform = transform;

            // See how far it is between horizontal pixels in world coordinates.
            pts = new PointF[] { new PointF(1, 0) };
            transform.Invert();
            transform.TransformVectors(pts);
            float dx = pts[0].X;

            // Generate points on the curve.
            List<PointF> points = new List<PointF>();
            for (float x = wxmin; x <= wxmax; x += dx)
                points.Add(new PointF(x, TheFunction(x)));

            // Use a thin pen.
            using (Pen thin_pen = new Pen(Color.Gray, 0))
            {
                // Draw the coordinate axes.
                gr.DrawLine(thin_pen, wxmin, 0, wxmax, 0);
                gr.DrawLine(thin_pen, 0, wymin, 0, wymax);
                for (float x = wxmin; x <= wxmax; x++)
                    gr.DrawLine(thin_pen, x, -0.5f, x, 0.5f);
                for (float y = wymin; y <= wymax; y++)
                    gr.DrawLine(thin_pen, -0.5f, y, 0.5f, y);

                // Draw the graph.
                thin_pen.Color = Color.Red;
                //thin_pen.Color = Color.Black;
                gr.DrawLines(thin_pen, points.ToArray());
            }
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:46,代码来源:Form1.cs

示例2: MatrixByVector

 public static PointF MatrixByVector(Matrix M, PointF P)
 {
     PointFSingleArray[0] = P;
     M.TransformVectors(PointFSingleArray);
     return PointFSingleArray[0];
 }
开发者ID:Shayan-To,项目名称:OpenMesh,代码行数:6,代码来源:Utils.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,代码来源:Form1.cs

示例4: 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,代码来源:Form1.cs

示例5: 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,代码来源:Form1.cs

示例6: updateConnectionPosition

            private void updateConnectionPosition()
            {
                if (mConnectionPoints != null)
                {
                    List<PointF> pointList = BrickLibrary.Instance.getConnectionPositionList(mPartNumber);
                    if (pointList != null)
                    {
                        Matrix rotation = new Matrix();
                        rotation.Rotate(mOrientation);
                        PointF[] pointArray = pointList.ToArray();
                        rotation.TransformVectors(pointArray);

                        PointF center = this.Center;
                        center.X += mOffsetFromOriginalImage.X;
                        center.Y += mOffsetFromOriginalImage.Y;

                        // in this function we assume the two arrays have the same size,
                        // i.e. mConnectionPoints.Count == pointArray.Length
                        // during the loading code we have created the mConnectionPoints with the
                        // same size as the part library.
                        for (int i = 0; i < pointList.Count; ++i)
                        {
                            mConnectionPoints[i].setPositionReservedForBrick(center.X + pointArray[i].X,
                                                                            center.Y + pointArray[i].Y);
                        }
                    }
                }
            }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:28,代码来源:LayerBrickBrick.cs

示例7: draw

        /// <summary>
        /// Draw some debug information like the chain bones
        /// </summary>
        /// <param name="g">the graphic context in which draw</param>
        /// <param name="areaInStud">the area in which draw</param>
        /// <param name="scalePixelPerStud">the current scale</param>
        public void draw(Graphics g, RectangleF areaInStud, double scalePixelPerStud)
        {
            int lastIndex = mBoneList.Count - 1;

            // draw the bones
            for (int i = 0; i < lastIndex; i++)
            {
                IKSolver.Bone_2D_CCD firstBone = mBoneList[i];
                IKSolver.Bone_2D_CCD nextBone = mBoneList[i+1];

                g.DrawLine(Pens.Black, (float)((firstBone.worldX - areaInStud.Left) * scalePixelPerStud),
                            (float)((-firstBone.worldY - areaInStud.Top) * scalePixelPerStud),
                            (float)((nextBone.worldX - areaInStud.Left) * scalePixelPerStud),
                            (float)((-nextBone.worldY - areaInStud.Top) * scalePixelPerStud));
            }

            // the last bone vector
            LayerBrick.Brick.ConnectionPoint endConnection = mBoneList[lastIndex].connectionPoint;
            if (!endConnection.IsFree)
            {
                // rotate the second target vector according to the orientation of the snapped connection
                PointF[] translation = { mLastBoneVector };
                Matrix rotation = new Matrix();
                rotation.Rotate(endConnection.ConnectedBrick.Orientation + endConnection.ConnectionLink.Angle + 180);
                rotation.TransformVectors(translation);

                // draw the translation
                IKSolver.Bone_2D_CCD lastBone = mBoneList[mBoneList.Count - 1];
                float endX = (float)(lastBone.worldX - areaInStud.Left);
                float endY = (float)(-lastBone.worldY - areaInStud.Top);
                g.DrawLine(Pens.Green, endX * (float)scalePixelPerStud, endY * (float)scalePixelPerStud,
                            (endX + translation[0].X) * (float)scalePixelPerStud,
                            (endY + translation[0].Y) * (float)scalePixelPerStud);
            }
        }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:41,代码来源:FlexMove.cs

示例8: ConvertSweepAngle

		internal static float ConvertSweepAngle(float sweepAngle, float startAngle, SpatialTransform transform, CoordinateSystem targetSystem)
		{
			PointF x = new PointF(100, 0);

			PointF[] startVector = new PointF[] { x };
			Matrix rotation = new Matrix();
			rotation.Rotate(startAngle);
			rotation.TransformVectors(startVector);

			PointF[] sweepVector = (PointF[])startVector.Clone();
			rotation.Reset();
			rotation.Rotate(sweepAngle);
			rotation.TransformVectors(sweepVector);
			rotation.Dispose();

			SizeF startVectorTransformed, sweepVectorTransformed;
			if (targetSystem == Graphics.CoordinateSystem.Destination)
			{
				startVectorTransformed = transform.ConvertToDestination(new SizeF(startVector[0]));
				sweepVectorTransformed = transform.ConvertToDestination(new SizeF(sweepVector[0]));
			}
			else
			{
				startVectorTransformed = transform.ConvertToSource(new SizeF(startVector[0]));
				sweepVectorTransformed = transform.ConvertToSource(new SizeF(sweepVector[0]));
			}

			// simply return the angle between the start and sweep angle, in the target system.
			return (int)Math.Round(Vector.SubtendedAngle(sweepVectorTransformed.ToPointF(), PointF.Empty, startVectorTransformed.ToPointF()));
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:30,代码来源:ArcPrimitive.cs

示例9: rotate

        protected void rotate(Layer.LayerItem item, Matrix rotation, float rotationAngle, bool adjustPivot)
        {
            // get the pivot point of the part before the rotation
            PointF pivot = item.Pivot;

            // change the orientation of the picture
            item.Orientation = (item.Orientation + rotationAngle);

            // for some items partially attached, we may don't want to adjust the pivot
            if (adjustPivot)
            {
                // adjust the position of the pivot for a group of items
                if (mItems.Count > 1)
                {
                    PointF[] points = { new PointF(pivot.X - mCenter.X, pivot.Y - mCenter.Y) };
                    rotation.TransformVectors(points);
                    // assign the new position
                    pivot.X = mCenter.X + points[0].X;
                    pivot.Y = mCenter.Y + points[0].Y;
                }

                // assign the new pivot position after rotation
                item.Pivot = pivot;
            }
        }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:25,代码来源:RotateItems.cs

示例10: TransformVectors

		public void TransformVectors  ()
		{
			Matrix matrix = new Matrix (2, 4, 6, 8, 10, 12);
			PointF [] pointsF = new PointF [] {new PointF (2, 4), new PointF (4, 8)};
			matrix.TransformVectors (pointsF);
						
			Assert.AreEqual (28, pointsF[0].X, "N#1");
			Assert.AreEqual (40, pointsF[0].Y, "N#2");
			Assert.AreEqual (56, pointsF[1].X, "N#3");
			Assert.AreEqual (80, pointsF[1].Y, "N#4");
			
			Point [] points = new Point [] {new Point (2, 4), new Point (4, 8)};
			matrix.TransformVectors (points);
			Assert.AreEqual (28, pointsF[0].X, "N#5");
			Assert.AreEqual (40, pointsF[0].Y, "N#6");
			Assert.AreEqual (56, pointsF[1].X, "N#7");
			Assert.AreEqual (80, pointsF[1].Y, "N#8");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:TestMatrix.cs

示例11: RotateImage

        public bool RotateImage( string sourceImagePath, int rotationDegree )
        {
            try
            {
                string fileExt = Path.GetExtension( sourceImagePath ).ToLowerInvariant().Trim( '.' );
                // create file name of the temp file
                string tempFilePath = getTempFileName( sourceImagePath, fileExt );

                using( Bitmap inputImage = new Bitmap( sourceImagePath ) )
                {
                    EncoderParameters encParams = null;
                    var encoder = getEncoder( fileExt, out encParams );

                    // calculate width and height of the new image
                    float iW = (float)inputImage.Width;
                    float iH = (float)inputImage.Height;

                    Matrix whRotation = new Matrix();
                    whRotation.Rotate( rotationDegree );
                    // rotate every vertex of our "image rectangle"
                    var tmpDims = new PointF[] { new PointF(0,0), new PointF( iW, 0 ), new PointF( iW, iH ), new PointF( 0, iH ) };
                    whRotation.TransformVectors( tmpDims );
                    // find extends
                    iW = Math.Abs( tmpDims.Max( x => x.X ) - tmpDims.Min( x => x.X ) );
                    iH = Math.Abs( tmpDims.Max( x => x.Y ) - tmpDims.Min( x => x.Y ) );

                    using( Bitmap tempBmp = new Bitmap( (int)Math.Ceiling( iW ), (int)Math.Ceiling( iH ) ) )
                    {
                        // rotate image
                        tempBmp.SetResolution( inputImage.HorizontalResolution, inputImage.VerticalResolution );
                        using( Graphics g = Graphics.FromImage( tempBmp ) )
                        {
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                            // rotate at the center
                            g.TranslateTransform( tempBmp.Width/2, tempBmp.Height/2 );
                            g.RotateTransform( rotationDegree );
                            g.TranslateTransform( -tempBmp.Width / 2, -tempBmp.Height / 2 );
                            g.DrawImage( inputImage,
                                new Point( ( tempBmp.Width - inputImage.Width ) / 2,
                                    ( tempBmp.Height - inputImage.Height ) / 2 ) );
                        }
                        tempBmp.Save( tempFilePath, encoder, encParams );
                    }
                }
                // now replace images
                File.Delete( sourceImagePath );
                File.Move( tempFilePath, sourceImagePath );
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:khushbug-optimus,项目名称:Hackathon,代码行数:54,代码来源:DefaultImageEditorService.cs

示例12: updateBitmap

            private void updateBitmap(bool redrawImage)
            {
                // create a bitmap if the text is not empty
                if (mText != "")
                {
                    // create a font to mesure the text
                    Font textFont = new Font(mTextFont.FontFamily, mTextFont.Size, mTextFont.Style);

                    Graphics graphics = Graphics.FromImage(mImage);
                    SizeF textFontSize = graphics.MeasureString(mText, textFont);
                    float halfWidth = textFontSize.Width * 0.5f;
                    float halfHeight = textFontSize.Height * 0.5f;

                    Matrix rotation = new Matrix();
                    rotation.Rotate(mOrientation);
                    // compute the rotated corners
                    PointF[] corners = new PointF[] { new PointF(-halfWidth, -halfHeight), new PointF(-halfWidth, halfHeight), new PointF(halfWidth, halfHeight), new PointF(halfWidth, -halfHeight) };
                    rotation.TransformVectors(corners);

                    PointF min = corners[0];
                    PointF max = corners[0];
                    for (int i = 1; i < 4; ++i)
                    {
                        if (corners[i].X < min.X)
                            min.X = corners[i].X;
                        if (corners[i].Y < min.Y)
                            min.Y = corners[i].Y;
                        if (corners[i].X > max.X)
                            max.X = corners[i].X;
                        if (corners[i].Y > max.Y)
                            max.Y = corners[i].Y;
                    }
                    // adjust the display area and selection area
                    mDisplayArea.Width = Math.Abs(max.X - min.X);
                    mDisplayArea.Height = Math.Abs(max.Y - min.Y);

                    // adjust the selection area (after adjusting the display area such as the center properties is correct)
                    Matrix translation = new Matrix();
                    translation.Translate(Center.X, Center.Y);
                    translation.TransformPoints(corners);

                    // then create the new selection area
                    mSelectionArea = new Tools.Polygon(corners);

                    if (redrawImage)
                    {
                        // now create a scaled font from the current one, to avoid aliasing
                        Font scaledTextFont = new Font(mTextFont.FontFamily, mTextFont.Size * ANTI_ALIASING_FONT_SCALE, mTextFont.Style);
                        mImage = new Bitmap(mImage, new Size((int)(textFontSize.Width * ANTI_ALIASING_FONT_SCALE), (int)(textFontSize.Height * ANTI_ALIASING_FONT_SCALE)));

                        // compute the position where to draw according to the alignment (if centered == 0)
                        float posx = 0;
                        if (this.TextAlignment == StringAlignment.Far)
                            posx = halfWidth;
                        else if (this.TextAlignment == StringAlignment.Near)
                            posx = -halfWidth;

                        graphics = Graphics.FromImage(mImage);
                        rotation = new Matrix();
                        rotation.Translate(mImage.Width / 2, mImage.Height / 2, MatrixOrder.Append);
                        graphics.Transform = rotation;
                        graphics.Clear(Color.Transparent);
                        graphics.SmoothingMode = SmoothingMode.HighQuality;
                        graphics.DrawString(mText, scaledTextFont, mTextBrush, posx * ANTI_ALIASING_FONT_SCALE, 0, mTextStringFormat);
                        graphics.Flush();
                    }
                }
            }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:68,代码来源:LayerTextCell.cs

示例13: rotate

 public void rotate(Matrix matrix)
 {
     PointF[] vector = { mLocalAttachOffsetFromCenter };
     matrix.TransformVectors(vector);
     mWorldAttachOffsetFromCenter = vector[0];
 }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:6,代码来源:RulerAttachementSet.cs

示例14: sComputeLocalOffsetFromLayerItem

 public static PointF sComputeLocalOffsetFromLayerItem(LayerBrick.Brick brick, PointF worldPositionInStud)
 {
     // get the brick pivot in world coordinate
     PointF brickPivot = brick.Pivot;
     // compute the offset from the brick center in world coordinate
     PointF offset = new PointF(worldPositionInStud.X - brickPivot.X, worldPositionInStud.Y - brickPivot.Y);
     // compute the rotation matrix of the brick in order to find the local offset
     Matrix matrix = new Matrix();
     matrix.Rotate(-brick.Orientation);
     PointF[] vector = { offset };
     matrix.TransformVectors(vector);
     // return the local offset
     return vector[0];
 }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:14,代码来源:RulerAttachementSet.cs

示例15: updateImage

            private void updateImage()
            {
                List<PointF> boundingBox = null;
                List<PointF> hull = null;
                mOriginalImageReference = BrickLibrary.Instance.getImage(mPartNumber, ref boundingBox, ref hull);
                // check if the image is not in the library, create one
                if (mOriginalImageReference == null)
                {
                    // add a default image in the library and ask it again
                    BrickLibrary.Instance.AddUnknownBrick(mPartNumber, (int)(mDisplayArea.Width), (int)(mDisplayArea.Height));
                    mOriginalImageReference = BrickLibrary.Instance.getImage(mPartNumber, ref boundingBox, ref hull);
                }
                // normally now, we should have an image
                // transform the bounding box of the part
                PointF[] boundingPoints = boundingBox.ToArray();
                Matrix rotation = new Matrix();
                rotation.Rotate(mOrientation);
                rotation.TransformVectors(boundingPoints);

                // get the min, max and the size of the bounding box
                PointF boundingMin = new PointF();
                PointF boundingMax = new PointF();
                PointF boundingSize = sGetMinMaxAndSize(boundingPoints, ref boundingMin, ref boundingMax);

                // store computationnal variable for optimization
                const float PIXEL_TO_STUD_RATIO = 1.0f / NUM_PIXEL_PER_STUD_FOR_BRICKS;

                // transform the hull to get the selection area
                PointF[] hullArray = hull.ToArray();
                rotation.TransformVectors(hullArray);

                // check if this picture has a specific hull
                if (hull != boundingBox)
                {
                    // get the bounding size from the hull
                    PointF hullMin = new PointF();
                    PointF hullMax = new PointF();
                    PointF hullSize = sGetMinMaxAndSize(hullArray, ref hullMin, ref hullMax);

                    // compute the offset between the hull and the normal bounding box
                    PointF deltaMin = new PointF(boundingMin.X - hullMin.X, boundingMin.Y - hullMin.Y);
                    PointF deltaMax = new PointF(boundingMax.X - hullMax.X, boundingMax.Y - hullMax.Y);
                    mOffsetFromOriginalImage = new PointF((deltaMax.X + deltaMin.X) * PIXEL_TO_STUD_RATIO * 0.5f,
                                                          (deltaMax.Y + deltaMin.Y) * PIXEL_TO_STUD_RATIO * 0.5f);

                    // overwrite the bounding size and min with the hull ones which are more precise
                    boundingSize = hullSize;
                    boundingMin = hullMin;
                }
                else
                {
                    mOffsetFromOriginalImage = new PointF(0, 0);
                }

                // set the size of the display area with the new computed bounding size, and recompute the snap to grid offset
                mDisplayArea.Width = boundingSize.X * PIXEL_TO_STUD_RATIO;
                mDisplayArea.Height = boundingSize.Y * PIXEL_TO_STUD_RATIO;
                mTopLeftCornerInPixel = new PointF(-boundingMin.X, -boundingMin.Y);

                // adjust the selection area after computing the new display area size to have a correct center
                // first we add the translation of the top left corner in pixel to the hull point already in pixel
                // then convert the pixel to studs, and finally add the top left corner in stud
                Matrix translation = new Matrix();
                translation.Translate(mTopLeftCornerInPixel.X, mTopLeftCornerInPixel.Y);
                translation.Scale(PIXEL_TO_STUD_RATIO, PIXEL_TO_STUD_RATIO, MatrixOrder.Append);
                translation.Translate(Center.X - (mDisplayArea.Width * 0.5f), Center.Y - (mDisplayArea.Height * 0.5f), MatrixOrder.Append);
                translation.TransformPoints(hullArray);

                // create the new selection area from the rotated hull
                mSelectionArea = new Tools.Polygon(hullArray);

                // clear the new images array for all the levels
                clearMipmapImages(0, mMipmapImages.Length - 1);
            }
开发者ID:henrihs,项目名称:bluebrick-id-fork,代码行数:74,代码来源:LayerBrickBrick.cs


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