Beispiel #1
0
        public static PointF TransformPoint(this Matrix m, PointF pt)
        {
            var p = new[] { pt };

            m.TransformPoints(p);
            return(p[0]);
        }
Beispiel #2
0
        /// <summary>
        /// Transforms cavas area to untransformed graphics canvas
        /// </summary>
        /// <param name="area"></param>
        /// <param name="matrix"></param>
        /// <returns></returns>
        protected static Rectangle ToGraphicsCanvas(RectangleF area, System.Drawing.Drawing2D.Matrix matrix)
        {
            if (!matrix.IsIdentity)
            {
                var pts = area.ToPointArray();
                matrix.TransformPoints(pts);
                // Enclosing rectangle aligned with graphics canvas and inflated to nearest integer values.
                area = pts.ToRectangleF();
            }

            // This is the area of the graphics canvas that needs to be refreshed when invalidating the image.
            var affectedArea = area.ToRectangle();

//                // proof of concept: draw affected area to screen aligned with graphics canvas
//                using (var orig = g.Transform.Clone())
//                {
//                    var areaToBeRendered = affectedArea;
//                    areaToBeRendered.Intersect(mapRect);
//                    g.ResetTransform();
//                    g.DrawRectangle(new Pen(Color.Red, 3f) {Alignment = System.Drawing.Drawing2D.PenAlignment.Inset},
//                        areaToBeRendered);
//                    g.Transform = orig;
//                }

            // allow for bleed and/or minor labelling misdemeanours
            affectedArea.Inflate(1, 1);

            return(affectedArea);
        }
Beispiel #3
0
        public static RectangleF TransformRect(this Matrix m, RectangleF rect)
        {
            var p = new[] { rect.TopLeft(), rect.BottomRight() };

            m.TransformPoints(p);
            return(RectangleF.FromLTRB(p[0].X, p[0].Y, p[1].X, p[1].Y));
        }
Beispiel #4
0
 public PointF[] GetPointsCopy(System.Drawing.Drawing2D.Matrix transform)
 {
     PointF[] points = new PointF[mPoints.Length];
     Array.Copy(mPoints, points, mPoints.Length);
     transform.TransformPoints(points);
     return(points);
 }
Beispiel #5
0
        //--------------------------------------------------------------------------------------------------------------
        // Performance benchmarking
        //--------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Just to mak sure the code is compiled etc
        /// </summary>
        /// <returns>A hash code that just prevents a too-smart compiler for removing redundent code. </returns>
        public static double PerformanceTestGDIConversion(int numberOfTests)
        {
            //TODO: HOW THE HELL DOES THIS TAKE 2MS TO COMPLETE???
            double[] numbers = new double[] { 5, 8, 232.5, 123321, 12, -18 };
            double   hash    = 0;

            for (int i = 1; i < numberOfTests; i++)
            {
                //I want to know that the transformation matrix is valid in GDI plus conversions.
                TransMatrix2D t1 = TransMatrix2D.FromTRS(
                    new Point2D(22.25, 31.75),
                    numbers[i % numbers.Length],
                    new Point2D(51, 37),
                    new Point2D(0.5, 0.25));

                GDIMatrix     g1 = t1.ToGDIPlusMatrix();
                TransMatrix2D t2 = TransMatrix2D.FromGDIPlusMatrix(g1);

                Point2D test = new Point2D(7.1, numbers[(i + 2) % numbers.Length]);
                Point2D p1   = t1.Transform(test);

                var temp = new PointF[] { test.AsPointF() };
                g1.TransformPoints(temp);
                Point2D p2 = new Point2D(temp[0]);

                Point2D p3 = t2.Transform(test);

                hash += p1.X + p2.X - p3.X;
            }

            return(hash);
        }
Beispiel #6
0
        public void scaleCurentFigure()
        {
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            System.Drawing.Drawing2D.Matrix test   = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0);
            // трансформация  из double[,] в pointF[]
            System.Drawing.PointF[] arr = new System.Drawing.PointF[rank];

            for (int i = 0; i < mainPoins2.Length; i++)
            {
                arr[i] = new System.Drawing.PointF((float)mainPoins2[i].X, (float)mainPoins2[i].Y);
            }
            // увеличение
            matrix.Scale(50, 50);
            // применение увеличения
            // matrix.Shear(-2, -2);
            matrix.TransformPoints(arr);
            // уже увеличеная фигура (точки)
            for (int i = 0; i < mainPoins2.Length; i++)
            {
                // arr[i] = new System.Drawing.PointF((float)mainPoins2[i].X, (float)mainPoins2[i].Y);
                mainPoins2[i].X = arr[i].X;
                mainPoins2[i].Y = arr[i].Y;
            }
            // setPointFToLinearr(arr);
        }
Beispiel #7
0
        /// <summary>
        /// Return cursor for command
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="zoomLevel"></param>
        /// <returns>null if coordinates are not fine</returns>
        public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);

            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected

            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return(this.cursor);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
        public static Point <float> Transform(this System.Drawing.Drawing2D.Matrix matrix, Point <float> point)
        {
            var a = AsArray(point.AsBCL());

            matrix.TransformPoints(a);
            return(a[0].AsLoyc());
        }
Beispiel #9
0
        public static PointF Transform(this System.Drawing.Drawing2D.Matrix matrix, PointF point)
        {
            var a = AsArray(point);

            matrix.TransformPoints(a);
            return(a[0]);
        }
Beispiel #10
0
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix matrix, RectangleF r)
 {
     s_tempPtsF[0] = new PointF(r.Left, r.Top);
     s_tempPtsF[1] = new PointF(r.Right, r.Bottom);
     matrix.TransformPoints(s_tempPtsF);
     return(MakeRectangle(s_tempPtsF[0], s_tempPtsF[1]));
 }
Beispiel #11
0
        // 画像表示に関するメソッド
        // https://imagingsolution.net/program/affine_image_transformations/

        /// <summary>
        /// アフィン変換行列(mat)に基づいて画像を描画する
        /// </summary>
        /// <param name="g">描画先のGraphicsオブジェクト</param>
        /// <param name="bmp">描画するBitmapオブジェクト</param>
        /// <param name="mat">アフィン変換行列</param>
        public static void DrawImage(this Graphics g, Bitmap bmp, System.Drawing.Drawing2D.Matrix mat)
        {
            if ((g == null) || (bmp == null))
            {
                return;
            }

            // 画像の画素の外側の領域
            var srcRect = new RectangleF(
                -0.5f,
                -0.5f,
                bmp.Width,
                bmp.Height
                );

            // 画像の左上、右上、左下の座標
            var points = new PointF[] {
                new PointF(srcRect.Left, srcRect.Top),   // 左上
                new PointF(srcRect.Right, srcRect.Top),  // 右上
                new PointF(srcRect.Left, srcRect.Bottom) // 左下
            };

            // アフィン変換で描画先の座標に変換する
            mat.TransformPoints(points);

            // 描画
            g.DrawImage(
                bmp,
                points,
                srcRect,
                GraphicsUnit.Pixel
                );
        }
Beispiel #12
0
        /// <summary>
        /// 画像の描画
        /// </summary>
        private void DrawImage()
        {
            if (_img == null)
            {
                return;
            }
            if (_bmp == null)
            {
                return;
            }

            // ピクチャボックスのクリア
            _gPicbox.Clear(picImage.BackColor);

            // 描画先の座標をアフィン変換で求める(左上、右上、左下の順)
            PointF[] destPoints = (PointF[])_srcPoints.Clone();
            // 描画先の座標をアフィン変換で求める(変換後の座標は上書きされる)
            _matAffine.TransformPoints(destPoints);

            // 描画
            _gPicbox.DrawImage(
                _bmp,
                destPoints,
                _srcRect,
                GraphicsUnit.Pixel
                );

            // 再描画
            picImage.Refresh();
        }
Beispiel #13
0
        public void TestMatrix2()
        {
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Rotate(30);
            mat.Translate(-20, 20);

            var at = new AffineCoordinateTransformation2D(mat);
            var atInv = at.Inverse();

            var p0 = new double[] { 50d, 50d };
            var pt = at.Transform(p0);
            at.Invert();
            var p1 = at.Transform(pt);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
            var p2 = atInv.Transform(pt);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);

            
            System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

            mat.TransformPoints(pts);
            System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
            System.Drawing.PointF ptt = pts[0];
            System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
            System.Drawing.Drawing2D.Matrix inv = mat.Clone();
            inv.Invert();
            inv.TransformPoints(ptts);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);

        }
Beispiel #14
0
 /// <summary>
 /// use matrix to transform point
 /// </summary>
 /// <param name="pts">contain the points to be transform</param>
 private void TransformPoints(Point[] pts)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
         1, 0, 0, 1, this.pictureBox.Width / 2, this.pictureBox.Height / 2);
     matrix.Invert();
     matrix.TransformPoints(pts);
 }
Beispiel #15
0
        public IEnumerable <System.Drawing.Rectangle> iterPreventRects()
        {
            var transform = new System.Drawing.Drawing2D.Matrix();
            var pts       = new System.Drawing.Point[1];

            int   circleCount = 16;
            float angleDelta  = 360 / circleCount;
            float angle       = 0;

            for (int i = 0; i < circleCount; ++i)
            {
                transform.Reset();
                transform.Rotate(angle);

                pts[0] = new System.Drawing.Point(0, 96);

                transform.TransformPoints(pts);

                var pt = pts[0];

                var hitRect = new System.Drawing.Rectangle(this.x + pt.X - 48, this.y + pt.Y - 48, 96, 96);
                // bool isCollision = _gamePlay.scene.hitTestCollision(snake.headPreventCollisionRect);

                //Console.WriteLine("{0} Prevent angle={1} hit={2}", snake, angle, isCollision);

                if (_headPreventCollisionRect.IntersectsWith(hitRect) == false)
                {
                    yield return(hitRect);
                }



                angle += angleDelta;
            }
        }
Beispiel #16
0
        /// <summary>
        /// Check if this command can be selected and return true in case it can
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);

            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected
            //float tmpX = LocationInPixelsX * zoomLevel;
            //float tmpY = LocationInPixelsY * zoomLevel;
            //float w = widthInPixels; //** zoomLevel;
            //float h = heightInPixels; //* zoomLevel;
            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];


            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #17
0
 public BoundingBox Transform(System.Drawing.Drawing2D.Matrix matrix)
 {
     System.Drawing.PointF[] points = new System.Drawing.PointF[2];
     points[0] = new System.Drawing.PointF((float)xMin, (float)yMin);
     points[1] = new System.Drawing.PointF((float)xMax, (float)yMax);
     matrix.TransformPoints(points);
     return(new BoundingBox(points[0].X, points[1].X, points[0].Y, points[1].Y));
 }
 public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint)
 {
     System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
     mat.RotateAt(angle, centerpoint);
     PointF[] arraypoints = new PointF[1];
     arraypoints[0] = dstpoint;
     mat.TransformPoints(arraypoints);
     dstpoint = arraypoints[0];
 }
Beispiel #19
0
        private void Dialogs_MouseMove(object sender, MouseEventArgs e)
        {
            if (movestart == null)
            {
                return;
            }

            if (FocusedPhrase == -1 && FocusedTimeline == -1 && !TranslateFocus)
            {
                return;
            }

            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            //m.Translate(Translate.X, Translate.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Scale(ScaleZoom, ScaleZoom, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Invert();

            Point movement = new Point(movestart.X - e.X, movestart.Y - e.Y);

            movement.X = -movement.X;
            movement.Y = -movement.Y;
            Point[] t = new Point[] { movement };
            m.TransformPoints(t);
            movement = t[0];

            if (FocusedPhrase != -1)
            {
                if (TreeOperationMode)
                {
                    dlg.MovePhraseTree(FocusedPhrase, movement);
                }
                else
                {
                    dlg.MovePhrase(FocusedPhrase, movement);
                }

                Changed = true;
            }
            else if (FocusedTimeline >= 0)
            {
                Point x = new Point(0, dlginstance.Timeline(FocusedTimeline).Ylocation);
                x.Offset(movement);
                dlginstance.Timeline(FocusedTimeline).Ylocation = x.Y;

                Changed = true;
            }
            else
            {
                Translate.X -= movestart.X - e.X;
                Translate.Y -= movestart.Y - e.Y;
                //Translate.Offset(movement);
            }

            movestart = e.Location;
            this.Refresh();
        }
        public override bool CalculateCalloutLocation(out PointF location, out CoordinateSystem coordinateSystem)
        {
            if (this.Roi.Points.Count < 3 || string.IsNullOrEmpty(this.Callout.Text))
            {
                base.Callout.Visible = false;
            }
            else
            {
                base.Callout.Visible = true;
            }

            if (!base.Callout.Visible || _userMovedCallout)
            {
                return(base.CalculateCalloutLocation(out location, out coordinateSystem));
            }

            SizeF calloutOffsetDestination = GetCalloutOffsetDestination();

            coordinateSystem = CoordinateSystem.Destination;
            base.AnnotationGraphic.CoordinateSystem = coordinateSystem;

            // first, move the callout by the same amount the vertex moved (if it moved at all).
            location = base.Callout.TextLocation + calloutOffsetDestination;

            PointF start  = this.Roi.Points[0];
            PointF vertex = this.Roi.Points[1];
            PointF end    = this.Roi.Points[2];

            base.AnnotationGraphic.ResetCoordinateSystem();

            double vectorAngle = -Vector.SubtendedAngle(start, vertex, end) / 2 + 180;

            PointF[] points = new PointF[] { start, end };

            using (Matrix rotation = new Matrix())
            {
                rotation.Rotate((float)vectorAngle);
                rotation.Translate(-vertex.X, -vertex.Y);
                rotation.TransformPoints(points);
            }

            float calloutMagnitude = new Vector3D(location.X - vertex.X, location.Y - vertex.Y, 0).Magnitude;

            Vector3D startVector = new Vector3D(points[0].X, points[0].Y, 0);

            if (FloatComparer.AreEqual(startVector.Magnitude, 0F, 0.01F))
            {
                startVector = new Vector3D(-1, 0, 0);
            }

            startVector = startVector / startVector.Magnitude * calloutMagnitude;

            location = new PointF(startVector.X + vertex.X, startVector.Y + vertex.Y);

            return(true);
        }
Beispiel #21
0
        public void Paint(Matrix2D T, double x0, double x1, Graphics G)
        {
            Pen             pen    = Pen;
            List <PointF[]> points = Evaluate(x0, x1);

            foreach (PointF[] i in points)
            {
                T.TransformPoints(i);
                G.DrawLines(pen, i);
            }
        }
Beispiel #22
0
        private System.Drawing.PointF _transRotPt(float angle, System.Drawing.PointF pt)
        {
            var trans1 = new System.Drawing.Drawing2D.Matrix();

            trans1.Rotate(angle);

            var pts1 = new System.Drawing.PointF[] { pt };

            trans1.TransformPoints(pts1);

            return(pts1[0]);
        }
        /// <summary>
        /// Converts a <see cref="PointF"/> from destination to source coordinates.
        /// </summary>
        /// <param name="destinationPoint"></param>
        /// <returns></returns>
        public PointF ConvertToSource(PointF destinationPoint)
        {
            Matrix inverse = this.CumulativeTransform.Clone();

            inverse.Invert();

            PointF[] points = new PointF[1];
            points[0] = destinationPoint;
            inverse.TransformPoints(points);

            return(points[0]);
        }
Beispiel #24
0
 private static Vector3D GetCurrentPosteriorVector(Vector3D imagePosterior, int sourceWidth, float adjustedSourceHeight, int rotation, float scaleX, float scaleY, bool flipX, bool flipY)
 {
     // figure out where the posterior direction went
     using (var transform = new Matrix())
     {
         var points = new[] { new PointF(sourceWidth * imagePosterior.X, adjustedSourceHeight * imagePosterior.Y) };
         transform.Rotate(rotation);
         transform.Scale(scaleX * (flipY ? -1 : 1), scaleY * (flipX ? -1 : 1));
         transform.TransformPoints(points);
         return(new Vector3D(points[0].X, points[0].Y, 0));
     }
 }
Beispiel #25
0
        private void _updateRotTransform()
        {
            _rotTransform = new System.Drawing.Drawing2D.Matrix();
            _rotTransform.Rotate(_head.rotation);

            var pts = new System.Drawing.PointF[] { new System.Drawing.PointF(0, _moveSpeedValue) };

            _rotTransform.TransformPoints(pts);

            var pt = pts[0];

            _speedDelta.X = pt.X;
            _speedDelta.Y = pt.Y;
        }
Beispiel #26
0
 public PdfRectangle Transform(System.Drawing.Drawing2D.Matrix transform)
 {
     System.Drawing.PointF[] points = { new System.Drawing.PointF(llx, lly), new System.Drawing.PointF(urx, ury) };
     float[] pts = { points[0].X, points[0].Y, points[1].X, points[1].Y };
     transform.TransformPoints(points);
     if (pts[0] > pts[2])
     {
         points[0].X = pts[2];
         points[1].X = pts[0];
     }
     if (pts[1] > pts[3])
     {
         points[0].Y = pts[3];
         points[1].Y = pts[1];
     }
     return(new PdfRectangle(points[0].X, points[0].Y, points[1].X, points[1].Y));
 }
        private void _joystick_movementEvent(JoystickEvent evt)
        {
            //Console.WriteLine("_joystick_movementEvent {0}", evt);

            if (_player == null) return;

            var transform = new System.Drawing.Drawing2D.Matrix();
            transform.Rotate(evt.angle);
            var pts = new System.Drawing.PointF[] { new PointF(0, 64) };
            transform.TransformPoints(pts);
            var pt2 = pts[0];

            //Console.WriteLine("_joystick_movementEvent angle={0} pt2={1}", evt.angle, pt2);
            _player.updateRotationWithRelatedPoint(pt2);

            _joystickDebugSprite.x = _player.x + (int)pt2.X;
            _joystickDebugSprite.y = _player.y + (int)pt2.Y;
        }
Beispiel #28
0
        float[] TransformPoints(float[] polygonXYs, System.Drawing.Drawing2D.Matrix transformMat)
        {
            //for example only

            PointF[] points       = new PointF[1];
            float[]  transformXYs = new float[polygonXYs.Length];

            for (int i = 0; i < polygonXYs.Length;)
            {
                points[0] = new PointF(polygonXYs[i], polygonXYs[i + 1]);
                transformMat.TransformPoints(points);

                transformXYs[i]     = points[0].X;
                transformXYs[i + 1] = points[0].Y;
                i += 2;
            }
            return(transformXYs);
        }
        private Bitmap Rotate(Bitmap image, float angle)
        {
            Bitmap bmp = new Bitmap(image.Width, image.Height);
            var    w   = (image.Width & 1) == 0 ? image.Width + 1 : image.Width;
            var    h   = (image.Height & 1) == 0 ? image.Height + 1 : image.Height;
            //центр изображения
            var center = new System.Drawing.Point(w / 2, h / 2);
            //Границы изображения
            var rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);

            using (var m = new System.Drawing.Drawing2D.Matrix())
            {
                System.Drawing.Point[] pts = new System.Drawing.Point[1];
                m.Translate(center.X, center.Y);
                m.Rotate(-angle);
                //m.Invert();
                for (int x = 0; x < image.Width; x++)
                {
                    for (int y = 0; y < image.Height; y++)
                    {
                        //Вектор к пикселу
                        pts[0] = new System.Drawing.Point(x - center.X, y - center.Y);
                        m.TransformPoints(pts);
                        if (!rect.Contains(pts[0]))
                        {
                            continue;
                        }
                        //bmp.SetPixel(pts[0].X, pts[0].Y, image.GetPixel(x, y));
                        bmp.SetPixel(x, y, image.GetPixel(pts[0].X, pts[0].Y));
                    }
                }
                for (int x = 0; x < bmp.Width; x++)
                {
                    for (int y = 0; y < bmp.Height; y++)
                    {
                        if (bmp.GetPixel(x, y).A == 0)
                        {
                            bmp.SetPixel(x, y, System.Drawing.Color.White);
                        }
                    }
                }
            }
            return(bmp);
        }
Beispiel #30
0
        /// <summary>
        /// Find location of PicBox relative to the Rovio.
        /// </summary>
        /// <param name="picBox">Picture box to check.</param>
        /// <param name="rect">Rectangle of the picture box's object on screen</param>
        /// <param name="distance">Distance to object</param>
        /// <param name="multiplierOne">First multiplier to change X position by.</param>
        /// <param name="multiplierTwo">Second multiplier to change X position by.</param>
        private void FindRelativeLocation(PictureBox picBox, DRectangle rect, double distance, int multiplierOne, int multiplierTwo)
        {
            picBox.Location = new System.Drawing.Point(picBoxRovio.Location.X + rect.X + rect.Width, picBoxRovio.Location.Y - (int)(distance * 20 * 3));

            double totalFOV   = distance * 100 * 0.93;
            double percentage = rect.X / (double)robot.cameraDimensions.X * 100;
            double newX       = percentage * (totalFOV / 100);

            DPoint newPosition = new System.Drawing.Point(picBoxRovio.Location.X - ((int)totalFOV / 2) + (int)newX * 2, picBox.Location.Y);

            using (matrix = new System.Drawing.Drawing2D.Matrix())
            {
                matrix.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
                matrix.Translate((float)-newX + 30f, -(float)(distance * multiplierOne * multiplierTwo));
                DPoint[] aPoints = { newPosition };
                matrix.TransformPoints(aPoints);
                picBox.Location = aPoints[0];
            }
        }
        /// <summary>
        /// Add a key point into this polyline link.
        /// </summary>
        /// <param name="x">X coordinate of the key point.</param>
        /// <param name="y">Y coordinate of the key point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        public void AddKeyPoint(float x, float y, GOM_Objects rgObjs)
        {
            if ( m_linkingStyle != GOM_Linking_Style.Polyline )
            {
                return;
            }

            System.Drawing.Drawing2D.Matrix	matrix;
            System.Drawing.PointF[]			rgPts, rgAllPts;
            System.Drawing.PointF			startPt, endPt;
            startPt	= StartPointInCanvas(rgObjs);
            endPt	= EndPointInCanvas(rgObjs);

            rgPts = new System.Drawing.PointF[2];
            rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

            rgAllPts[0].X = startPt.X;
            rgAllPts[0].Y = startPt.Y;
            for(int i=0; i<m_keyPts.Count; i++)
            {
                rgAllPts[1+i].X = m_keyPts[i].x;
                rgAllPts[1+i].Y = m_keyPts[i].y;
            }
            rgAllPts[rgAllPts.Length-1].X = endPt.X;
            rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

            for(int i=0; i<(rgAllPts.Length-1); i++)
            {
                rgPts[0].X = rgAllPts[i+1].X;
                rgPts[0].Y = rgAllPts[i+1].Y;
                rgPts[1].X = x;
                rgPts[1].Y = y;

                matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                matrix.TransformPoints(rgPts);

                float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                matrix.Reset();
                matrix.Rotate(-angle);
                matrix.TransformPoints(rgPts);

                if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                {
                    GOM_Point point = new GOM_Point();
                    point.x = x;
                    point.y = y;
                    m_keyPts.Insert(i, point);
                    return;
                }
            }
        }
		private PointF ConvertInvariantToDestination(PointF invariantPoint)
		{
			PointF xVector = new PointF(100, 0);
			SizeF xVectorTransformed = base.SpatialTransform.ConvertToDestination(new SizeF(xVector));

			//figure out where the source x-axis went in destination
			int rotation = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector));
			if (rotation < 0)
				rotation += 360;

			Matrix m = new Matrix();
			m.Rotate(rotation);
			PointF[] pt = { invariantPoint };
			m.TransformPoints(pt);
			m.Dispose();

			return new PointF(base.Location.X + pt[0].X, base.Location.Y + pt[0].Y);
		}
        public System.Drawing.PointF PointToObject(System.Drawing.PointF pt)
        {
            System.Drawing.Drawing2D.Matrix	matrix;
            System.Drawing.RectangleF		rc;
            System.Drawing.PointF[]			rgPts;

            rc = this.BoundingBox;

            rgPts = new System.Drawing.PointF[1];
            rgPts[0].X = pt.X;
            rgPts[0].Y = pt.Y;

            matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(-this.xOffset, -this.yOffset);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Translate(-(rc.Left + rc.Right) / 2, -(rc.Top + rc.Bottom) / 2);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Rotate(-this.rotation);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Translate((rc.Left + rc.Right) / 2, (rc.Top + rc.Bottom) / 2);
            matrix.TransformPoints(rgPts);

            return rgPts[0];
        }
		private static Vector3D GetCurrentPosteriorVector(Vector3D imagePosterior, int sourceWidth, float adjustedSourceHeight, int rotation, float scaleX, float scaleY, bool flipX, bool flipY)
		{
			// figure out where the posterior direction went
			using (var transform = new Matrix())
			{
				var points = new[] {new PointF(sourceWidth*imagePosterior.X, adjustedSourceHeight*imagePosterior.Y)};
				transform.Rotate(rotation);
				transform.Scale(scaleX*(flipY ? -1 : 1), scaleY*(flipX ? -1 : 1));
				transform.TransformPoints(points);
				return new Vector3D(points[0].X, points[0].Y, 0);
			}
		}
Beispiel #35
0
        private void GraphicsView_MouseMove(object sender, MouseEventArgs e)
        {
            if (movestart == null) return;
            if (!TranslateFocus)
                return;
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            //m.Translate(Translate.X, Translate.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Scale(ZoomScale, ZoomScale, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Invert();

            Point movement = new Point(movestart.X - e.X, movestart.Y - e.Y);
            movement.X = -movement.X;
            movement.Y = -movement.Y;
            Point[] t = new Point[] { movement };
            m.TransformPoints(t);
            movement = t[0];

            Translate.X -= movestart.X - e.X;
            Translate.Y -= movestart.Y - e.Y;

            movestart = e.Location;

            HighPrecisionDraw = false;
            this.Refresh();
        }
Beispiel #36
0
			/// <summary>
			/// Bisects the inner angle formed by <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
			/// </summary>
			/// <remarks>
			/// <para>
			/// Based largely on <see cref="ProtractorRoiCalloutLocationStrategy"/>.
			/// </para>
			/// <para>
			/// The return value is a point within the angle such that the line segment
			/// from this point to <paramref name="point2"/> has the specified <paramref name="magnitude"/> and bisects the angle
			/// <paramref name="point1"/> <paramref name="point2"/> <paramref name="point3"/>.
			/// </para>
			/// </remarks>
			private static PointF BisectAngle(PointF point1, PointF point2, PointF point3, float magnitude)
			{
				PointF[] points = new PointF[] {point1, point3};
				using (Matrix2D rotation = new Matrix2D())
				{
					rotation.Rotate((float) (-Vector.SubtendedAngle(point1, point2, point3)/2 + 180));
					rotation.Translate(-point2.X, -point2.Y);
					rotation.TransformPoints(points);
				}

				Vector3D result = new Vector3D(points[0].X, points[0].Y, 0);
				if (FloatComparer.AreEqual(result.Magnitude, 0F, 0.01F))
					result = new Vector3D(-1, 0, 0);
				result = result/result.Magnitude*magnitude;

				return new PointF(point2.X - result.X, point2.Y - result.Y);
			}
Beispiel #37
0
        /// <summary>
        /// Find location of PicBox relative to the Rovio.
        /// </summary>
        /// <param name="picBox">Picture box to check.</param>
        /// <param name="rect">Rectangle of the picture box's object on screen</param>
        /// <param name="distance">Distance to object</param>
        /// <param name="multiplierOne">First multiplier to change X position by.</param>
        /// <param name="multiplierTwo">Second multiplier to change X position by.</param>
        private void FindRelativeLocation(PictureBox picBox, DRectangle rect, double distance, int multiplierOne, int multiplierTwo)
        {
            picBox.Location = new System.Drawing.Point(picBoxRovio.Location.X + rect.X + rect.Width, picBoxRovio.Location.Y - (int)(distance * 20 * 3));

            double totalFOV = distance * 100 * 0.93;
            double percentage = rect.X / (double)robot.cameraDimensions.X * 100;
            double newX = percentage * (totalFOV / 100);

            DPoint newPosition = new System.Drawing.Point(picBoxRovio.Location.X - ((int)totalFOV / 2) + (int)newX*2, picBox.Location.Y);
            using (matrix = new System.Drawing.Drawing2D.Matrix())
            {
                matrix.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
                matrix.Translate((float)-newX + 30f, -(float)(distance * multiplierOne * multiplierTwo));
                DPoint[] aPoints = { newPosition };
                matrix.TransformPoints(aPoints);
                picBox.Location = aPoints[0];
            }
        }
Beispiel #38
0
        private void HardFit()
        {
            /*
             * Rotate the rectangle so that top-left is centered at the top with bot-right at the bottom center. This angle is BaseTheta
             * Find the min/max x/y
             * Use those and find the efficiency of that ellipse
             * Rotate by PI/2/ANGLETRYCOUNT for PI/2 rad's (90 degs), running this same algorithm for each rotation
             * Use the most efficient, using -(BaseTheta+Theta) as the rotation of the ellipse
             */

            PointF[] Pts = (PointF[])mImgSec.PixelsUsed().SelectMany(p => new PointF[]{new PointF((float)p.X, (float)p.Y)});
            System.Drawing.Drawing2D.Matrix BaseRotator = new System.Drawing.Drawing2D.Matrix(), StepRotate = new System.Drawing.Drawing2D.Matrix();
            // |\ = ATan(Width/Height)  so |\   |
            // | \                         | \  |
            // |  \                        |  \ |
            // |___\                       |___\| = -Atan(W/H)

            float BaseTheta = (float)(-Math.Atan((double)mImgSec.Width / (double)mImgSec.Height));
            BaseRotator.Rotate(BaseTheta);
            StepRotate.Rotate((float)Math.PI / 2f / (float)ANGLETRYCOUNT);
            BaseRotator.TransformPoints(Pts);
            double BestFit = 0d,temp;
            int BestChoice = -1;
            SizeF BestDim = new SizeF(),tempDim;
            for(int i = 0; i < ANGLETRYCOUNT - 1; i++, StepRotate.TransformPoints(Pts))
            {
                if((temp = GetFit(Pts, out tempDim)) > BestFit)
                {BestChoice = i; BestFit = temp;BestDim = tempDim;}
            }

            mRotation = -(BaseTheta+BestChoice*Math.PI / 2d / (double)ANGLETRYCOUNT);
            mEllWidth = BestDim.Width;
            mEllHeight = BestDim.Height;
            return;
        }
Beispiel #39
0
        /// <summary>
        ///获取低压台区网络图
        /// </summary>
        /// <param name="tqcode"></param>
        /// <returns></returns>
        public static Bitmap GetDytqMap(string tqcode ,int width,int height) {
            int w = width;
            int h = height;
            Bitmap bp = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(bp);
            IList<PS_xl> list = Ebada.Client.ClientHelper.PlatformSqlMap.GetList<PS_xl>("where linecode like '" + tqcode + "%' and linevol='0.4'");
            RectangleF rf = RectangleF.Empty;
            int bl = 10000;
            Dictionary<PS_xl, IList<PS_gt>> gts = new Dictionary<PS_xl, IList<PS_gt>>();
            List<PS_gtsb> gtsbs = new List<PS_gtsb>();

            foreach (PS_xl xl in list) {
                IList<PS_gt> gtlist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gt>("where linecode ='" + xl.LineCode + "' order by gtcode");
                if (gtlist.Count == 0) continue;
                IList<PS_gtsb> gtsblist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gtsb>(" where sbtype like '17%' and  gtid in (select gtid from ps_gt where linecode ='" + xl.LineCode + "')");
                gtsbs.AddRange(gtsblist);
                IList<PS_gt> gtlist2 = new List<PS_gt>();
                foreach (PS_gt gt in gtlist) {
                    if (gt.gtLat == 0 || gt.gtLon == 0) continue;
                    gtlist2.Add(gt);
                    if (rf.IsEmpty)
                        rf = new RectangleF((float)gt.gtLon*bl, (float)gt.gtLat*bl, 1f, 1f);
                    else
                        rf=RectangleF.Union(rf,new RectangleF((float)gt.gtLon*bl, (float)gt.gtLat*bl,1f,1f));
                    //rf..Inflate((float)gt.gtLon, (float)gt.gtLat);
                }
                gts.Add(xl, gtlist2);
            }
            DataTable gtbhtable = Ebada.Core.ConvertHelper.ToDataTable(gtsbs,typeof(PS_gtsb));
            //g.TranslateTransform(-rf.X, -rf.Y);
            rf.Inflate(3, 3);
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(-rf.X, -rf.Y);
            float f1=w / rf.Width;
            float f2=h/rf.Height;
            float scale = Math.Min(f1,f2);


            matrix.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
            if (f1 < f2)
                matrix.Translate(0, (h - f1 * rf.Height) / 2, System.Drawing.Drawing2D.MatrixOrder.Append);
            else
                matrix.Translate((w - f2 * rf.Width) / 2, 0, System.Drawing.Drawing2D.MatrixOrder.Append);
            
            List<PointF> plist = new List<PointF>();
            g.Clear(Color.White);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Font f = new Font("宋体", 9);
            PointF p0 = Point.Empty;
            Pen pen0 = new Pen(Color.Blue);
            pen0.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            List<string> gt0list = new List<string>();//记录重叠杆塔
            List<RectangleF> gtboxlist = new List<RectangleF>();
            foreach (PS_xl xl in gts.Keys) {
                plist.Clear();
                foreach (PS_gt gt in gts[xl]) {
                    plist.Add(new PointF((float)gt.gtLon*bl, (float)gt.gtLat*bl));
                }
                if (plist.Count <2) continue;
                PointF[] pts=plist.ToArray();

                matrix.TransformPoints(pts);
                for(int i=0;i<pts.Length;i++){
                    pts[i].Y = h - pts[i].Y;
                }
                g.DrawLines(Pens.Blue,pts );
                bool b1 = Math.Abs(pts[0].X - pts[1].X) > Math.Abs(pts[0].Y - pts[1].Y);
                Point offset = new Point(b1 ? 0 : 20, b1 ? 20 : 0);
                int gtnum = 0;
                for(int i=0;i<pts.Length;i++) {
                    PS_gt gt =gts[xl][i];
                    if (gt.gtLat==0.0m||gt.gtLon==0.0m) continue;
                    if (gt.gtJg == "是" && i==0) {
                        if (xl.ParentID.Length > 10) continue;//台区下干线除外
                        PointF pf0 = pts[i];
                        bool ret = false;
                        if (gt0list.Contains(xl.ParentID)) {
                            
                            foreach (RectangleF rtf in gtboxlist) {
                                if (rtf.Contains(pf0)) { ret = true; break; }
                            }
                        } else {
                            gt0list.Add(xl.ParentID);
                        }
                        if (ret) continue;
                        RectangleF rtf0 = RectangleF.Empty;
                        rtf0.Location = pf0;
                        rtf0.Inflate(10, 10);
                        gtboxlist.Add(rtf0);

                    }
                    
                    DataRow[] rows= gtbhtable.Select("gtid='" + gt.gtID + "'");
                    int n = 1;
                    foreach (DataRow row in rows) {
                        PS_gtsb gtsb = Ebada.Core.ConvertHelper.RowToObject<PS_gtsb>(row);
                        n *= -1;
                        PointF pf = new PointF(pts[i].X + (n * offset.X), pts[i].Y + (n * offset.Y));
                        RectangleF rtf = Rectangle.Empty;
                        rtf.Location = pf;
                        rtf.Inflate(12, 5);
                        Rectangle rt =Rectangle.Round(rtf);
                        g.DrawLine(Pens.Red, pts[i], pf);
                        g.FillRectangle(Brushes.White, rt);
                        g.DrawRectangle(Pens.Red, rt);
                        string num= gtsb.sbModle.Substring(0,1);
                        if (gtsb.sbNumber > 1) num = num + "x" + gtsb.sbNumber;
                        StringFormat sf =new StringFormat();
                        sf.Alignment= StringAlignment.Center;
                        
                        //sf.LineAlignment= StringAlignment.Center;
                        g.DrawString(num, f, Brushes.Red, rtf,sf);
                        
                        if (n == 1) break;
                    }
                    g.FillEllipse(Brushes.White, pts[i].X - 5, pts[i].Y - 5, 10, 10);
                    if (gt.gtJg == "是") {
                        g.DrawEllipse(pen0, pts[i].X - 5, pts[i].Y - 5, 10, 10);
                    } else {
                        gtnum += 1;
                        g.DrawEllipse(Pens.Blue, pts[i].X - 5, pts[i].Y - 5, 10, 10);
                        g.DrawString((int)gt.gtHeight + "/" + (gtnum), f, Brushes.Black, pts[i].X - 10, pts[i].Y + 5);

                    }
                }
                p0 = Point.Empty;
            }
            Hashtable ht_linenum = new Hashtable();
            ht_linenum.Add("一线", "1");
            ht_linenum.Add("二线", "2");
            ht_linenum.Add("三线", "3");
            ht_linenum.Add("四线", "4");
            foreach (PS_xl xl in gts.Keys) {
                plist.Clear();
                foreach (PS_gt gt in gts[xl]) {
                    plist.Add(new PointF((float)gt.gtLon * bl, (float)gt.gtLat * bl));
                }
                if (plist.Count < 2) continue;
                PointF[] pts = plist.ToArray();

                matrix.TransformPoints(pts);
                for (int i = 0; i < pts.Length; i++) {
                    pts[i].Y = h - pts[i].Y;
                }
                PointF curgt = pts[0];
                for (int i = 1; i < pts.Length; i++) {
                    PS_gt gt = gts[xl][i];
                    if (gt.gtSpan > 1) {
                        drawSpan(g,(int)gt.gtSpan, curgt.X, curgt.Y, pts[i].X, pts[i].Y);
                    }
                    curgt = pts[i];
                }
                object obj = ht_linenum[xl.lineNum] ?? "2";
                string linenum = "X" + obj.ToString();
                drawLineModel(g, xl.WireType+linenum, pts[pts.Length - 2].X, pts[pts.Length -2].Y, pts[pts.Length - 1].X, pts[pts.Length - 1].Y);
            }

            //绘制10线路方向

            IList<PS_xl> xllist0 = Client.ClientHelper.PlatformSqlMap.GetList<PS_xl>("where parentid='" + tqcode + "' and linevol ='0.4' ");
            
            foreach (PS_xl xl0 in xllist0) {

                IList<PS_gt> gtlist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gt>("where linecode='" + xl0.LineCode + "' order by gtcode");
                if (gtlist.Count >= 2) {
                    PointF p1 = new PointF((float)gtlist[0].gtLon * bl, (float)gtlist[0].gtLat * bl);
                    PointF p2 = new PointF((float)gtlist[1].gtLon * bl, (float)gtlist[1].gtLat * bl);
                    PointF[] pts = new PointF[] { p1, p2 };
                    matrix.TransformPoints(pts);
                    //drawArrow(g, pts[0].X, h - pts[0].Y, pts[1].X, h - pts[1].Y);
                }

            }
            PS_tq tq = Client.ClientHelper.PlatformSqlMap.GetOne<PS_tq>("where tqcode='" + tqcode + "'");
            if (tq != null) {
                IList<PS_gt> gtlist = Client.ClientHelper.PlatformSqlMap.GetList<PS_gt>("where linecode='" + tq.xlCode2 + "' order by gtcode");
                if (gtlist.Count>1) {
                    for(int i=0;i<gtlist.Count;i++) {
                        if (gtlist[i].gtCode == tq.gtID) {
                            if (i > 0) {
                                PointF p1 = new PointF((float)gtlist[i-1].gtLon * bl, (float)gtlist[i-1].gtLat * bl);
                                PointF p2 = new PointF((float)gtlist[i].gtLon * bl, (float)gtlist[i].gtLat * bl);
                                PointF[] pts = new PointF[] { p1, p2 };
                                matrix.TransformPoints(pts);
                                drawArrow(g, pts[0].X, h - pts[0].Y, pts[1].X, h - pts[1].Y);
                            }
                            break;
                        }
                    }
                }
            }
            //绘制指南针
            g.TranslateTransform(width - 50, 20);
            g.ScaleTransform(1.5f, 1.5f);
            draw指南针(g);
            return bp;
        }
            public void TestMatrix()
            {
                SharpMap.Geometries.Point p = new Point(10, 10);
                var b = p.AsBinary();

                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);
                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF ptt = pts[0];
                System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
Beispiel #41
0
        /// <summary>
        /// Update function of map. Calls Bayes filtering and handles the rotation and translation of all map objects.
        /// </summary>
        private void Update(object sender, EventArgs e)
        {
            lock (robot.mapLock)
            {
                Bayes(true, preySensor, ref preyProbability);
                Bayes(false, obstacleSensor, ref obstacleProbability);
                bBayes = new Bitmap(bMap.Size.Width, bMap.Size.Height);
                SetNewRovioPosition();

                // Run AStar if there is a suitable destination and draw it on the map.
                using (graphics = Graphics.FromImage(bBayes))
                {
                    AStar astar = new AStar(finalMap.GetLength(0), finalMap.GetLength(1));
                    astar.Build(finalMap, new DPoint(destination.X, destination.Y), new DPoint((picBoxRovio.Location.X / 10) + (picBoxRovio.Width / 10 / 2), picBoxRovio.Location.Y / 10));
                    aStarPath = astar.path;
                    for (int i = 0; i < maxX; i++)
                    {
                        for (int j = 0; j < maxY; j++)
                        {
                            graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(preyProbability[i, j] * 255), System.Drawing.Color.DarkRed)), new DRectangle(i * 10, j * 10, 10, 10));
                            graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(obstacleProbability[i, j] * 255), System.Drawing.Color.DarkBlue)), new DRectangle(i * 10, j * 10, 10, 10));
                            if (astar.inPath[i, j])
                                graphics.FillRectangle(new SolidBrush(DColor.Red), new DRectangle(i * 10, j * 10, 10, 10));
                        }
                    }
                }
                picBoxBayes.Image = bBayes;

                // Check which cells are within the viewing cone.
                if (viewConePoints != null)
                {
                    for (int i = 0; i < maxX; i++)
                    {
                        for (int j = 0; j < maxY; j++)
                        {
                            DPoint a = new DPoint(i * 10 + 1, j * 10 + 1); // Top left
                            DPoint b = new DPoint((i + 1) * 10 - 1, j * 10 + 1); // Top right
                            DPoint c = new DPoint(i * 10 + 1, (j + 1) * 10 - 1); // Bottom left
                            DPoint d = new DPoint((i + 1) * 10 - 1, (j + 1) * 10 - 1); // Bottom right
                            if (!(PointInPolygon(a, viewConePoints) || PointInPolygon(b, viewConePoints)
                                || PointInPolygon(c, viewConePoints) || PointInPolygon(d, viewConePoints)))
                            {
                                isCellVisible[i, j] = false;
                            }
                            else
                            {
                                preySensor[i, j] = false;
                                obstacleSensor[i, j] = false;
                                isCellVisible[i, j] = true;
                            }
                        }
                    }
                }

                if (robot.GetType() == typeof(Rovio.PredatorMap))
                {
                    if (robot.IsPreySeen())
                    {
                        FindRelativeLocation(picBoxPrey, robot.preyRectangle, robot.GetPreyDistance(), 1, 1);

                        try
                        {
                            preySensor[(int)((picBoxPrey.Location.X / 10) + 1.5), (int)((picBoxPrey.Location.Y / 10) + 1.5)] = true;
                        } catch { }
                    }
                    else
                        picBoxPrey.Hide();

                    if ((robot as Rovio.BaseArena).IsObstacleSeen())
                    {
                        // Find obstacle position relative to the Rovio's position.
                        FindRelativeLocation(picBoxObstacle, robot.obstacleRectangle, robot.GetObstacleDistance(), 40, 3);
                        try
                        {
                            int p = (int)((picBoxObstacle.Location.X / 10) + 0.5);
                            int q = (int)((picBoxObstacle.Location.Y / 10) + 0.5);

                            // Populate 3x3 area with the obstacle.
                            for (int i = -1; i <= 1; i++)
                                for (int j = -1; j <= 1; j++)
                                    obstacleSensor[(int)((picBoxObstacle.Location.X / 10) + i), (int)((picBoxObstacle.Location.Y / 10) + j)] = true;
                        }
                        catch { }
                    }
                    else
                        picBoxObstacle.Hide();
                }

                // Rotate the Rovio icon to the angle that the robot physically faces.
                System.Drawing.Drawing2D.Matrix matrixRovio = new System.Drawing.Drawing2D.Matrix();
                matrixRovio.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
                matrixRovio.Translate(0f, -0f);
                DPoint[] rovioMovementPoints = {new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height/2)),
                                                    new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) - 69, picBoxRovio.Location.Y-150),
                                                    new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) + 69, picBoxRovio.Location.Y-150)};
                matrixRovio.TransformPoints(rovioMovementPoints);

                if ((robot as Rovio.BaseArena).IsObstacleSeen())
                {
                    // Get the left and right points of the obstacle in the viewing cone and orientate accordingly.
                    DPoint leftPoint = new DPoint(picBoxObstacle.Location.X - (picBoxObstacle.Width / 2), picBoxObstacle.Location.Y - 15);
                    DPoint rightPoint = leftPoint;
                    using (matrix = new System.Drawing.Drawing2D.Matrix())
                    {
                        matrix.RotateAt((float)robot.cumulativeAngle, leftPoint);
                        matrix.Translate(0, -0f);

                        DPoint[] tempPointArr = { leftPoint };
                        matrix.TransformPoints(tempPointArr);
                        leftPoint = tempPointArr[0];

                        // Transform the right point relative to the position of the left.
                        matrix = new System.Drawing.Drawing2D.Matrix();
                        matrix.RotateAt((float)robot.cumulativeAngle, leftPoint);
                        matrix.Translate(30, 0);
                        tempPointArr[0] = new DPoint(0, 0);
                        matrix.TransformPoints(tempPointArr);
                        rightPoint = tempPointArr[0];
                    }

                    // Check if all points are still within the viewing cone. If not, skip over them.
                    if (PointInPolygon(leftPoint, rovioMovementPoints) && PointInPolygon(rightPoint, rovioMovementPoints))
                        rovioMovementPoints = new DPoint[] { rovioMovementPoints[0], rovioMovementPoints[1], leftPoint, rightPoint, rovioMovementPoints[2] };
                }

                viewConePoints = rovioMovementPoints;
                Bitmap rotated = new Bitmap(bRovio.Width + 70, bRovio.Height + 70);
                rotated.SetResolution(bRovio.HorizontalResolution, bRovio.VerticalResolution);

                using (graphics = Graphics.FromImage(rotated))
                {
                    graphics.TranslateTransform(bRovio.Width / 2, bRovio.Height / 2);
                    graphics.RotateTransform((float)robot.cumulativeAngle);
                    graphics.TranslateTransform(-bRovio.Width / 2, -bRovio.Height / 2);
                    graphics.DrawImage(bRovio, new DPoint(0, 0));

                    picBoxRovio.Size = new Size(27, 24);
                    picBoxRovio.Image = rotated;

                    picBoxCone.Location = new DPoint(picBoxRovio.Location.X - (bCone.Width / 2) + (bRovio.Width / 2), picBoxRovio.Location.Y - bCone.Height + (bRovio.Height / 2));
                    picBoxCone.Size = new Size(900, 500);
                    picBoxCone.Image = rotated;

                    picBoxCone.Location = new DPoint(0, 0);
                    picBoxCone.Size = new Size(260, 300);
                }

                Bitmap newCone = new Bitmap(260, 300);
                using (graphics = Graphics.FromImage(newCone))
                {
                    graphics.FillPolygon(new SolidBrush(DColor.FromArgb(100, DColor.ForestGreen)), viewConePoints);
                    picBoxCone.Image = newCone;
                }
            }
        }
Beispiel #42
0
 /// <summary>
 /// use matrix to transform point
 /// </summary>
 /// <param name="pts">contain the points to be transformed</param>
 private void TransformPoints(Point[] pts)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
         1, 0, 0, 1, m_sizePictureBox.Width / 2, m_sizePictureBox.Height / 2);
     matrix.Invert();
     matrix.TransformPoints(pts);
 }
Beispiel #43
0
 public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint)
 {
     System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
     mat.RotateAt(angle, centerpoint);
     PointF[] arraypoints = new PointF[1];
     arraypoints[0] =  dstpoint;
     mat.TransformPoints(arraypoints);
     dstpoint = arraypoints[0];
 }
Beispiel #44
0
        public void Draw2dTextures(Draw2dData[] todraw, int textureid, float angle)
        {
            GL.PushAttrib(AttribMask.ColorBufferBit);
            GL.BindTexture(TextureTarget.Texture2D, textureid);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);

            VertexPositionTexture[] vertices;
            ushort[] indices;
            if (todraw.Length >= draw2dtexturesMAX)
            {
                vertices = new VertexPositionTexture[todraw.Length * 4];
                indices = new ushort[todraw.Length * 4];
            }
            else
            {
                if (draw2dtexturesVertices == null)
                {
                    draw2dtexturesVertices = new VertexPositionTexture[draw2dtexturesMAX * 4];
                    draw2dtexturesIndices = new ushort[draw2dtexturesMAX * 4];
                }
                vertices = draw2dtexturesVertices;
                indices = draw2dtexturesIndices;
            }
            ushort i = 0;
            foreach (Draw2dData v in todraw)
            {
                RectangleF rect;
                if (v.inAtlasId == null)
                {
                    rect = new RectangleF(0, 0, 1, 1);
                }
                else
                {
                    rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, d_Terrain.texturesPacked);
                }
                float x2 = v.x1 + v.width;
                float y2 = v.y1 + v.height;

                PointF[] pnts = new PointF[4] {
                    new PointF(x2, y2),
                    new PointF(x2,v.y1),
                    new PointF(v.x1,v.y1),
                    new PointF(v.x1,y2)};
                if (angle != 0)
                {
                    System.Drawing.Drawing2D.Matrix mx=new System.Drawing.Drawing2D.Matrix();
                    mx.RotateAt(angle, new PointF(v.x1+v.width/2,v.y1+v.height/2));
                    mx.TransformPoints(pnts);
                }

                vertices[i] = new VertexPositionTexture(pnts[0].X, pnts[0].Y, 0, rect.Right, rect.Bottom, v.color);
                vertices[i + 1] = new VertexPositionTexture(pnts[1].X, pnts[1].Y, 0, rect.Right, rect.Top, v.color);
                vertices[i + 2] = new VertexPositionTexture(pnts[2].X, pnts[2].Y, 0, rect.Left, rect.Top, v.color);
                vertices[i + 3] = new VertexPositionTexture(pnts[3].X, pnts[3].Y, 0, rect.Left, rect.Bottom, v.color);
                indices[i] = i;
                indices[i + 1] = (ushort)(i + 1);
                indices[i + 2] = (ushort)(i + 2);
                indices[i + 3] = (ushort)(i + 3);
                i += 4;
            }
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            unsafe
            {
                fixed (VertexPositionTexture* p = vertices)
                {
                    GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte*)p));
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte*)p));
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte*)p));
                    GL.DrawElements(BeginMode.Quads, i, DrawElementsType.UnsignedShort, indices);
                }
            }
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            GL.Enable(EnableCap.DepthTest);
            GL.PopAttrib();
        }
        /// <summary>
        /// Indicates whether a given point is on this link.
        /// </summary>
        /// <param name="x">X coordinate of the given point.</param>
        /// <param name="y">Y coordinate of the given point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        /// <returns>Whether a given point is on this link.</returns>
        public bool IsPointOnLink(float x, float y, GOM_Objects rgObjs)
        {
            switch (m_linkingStyle)
            {
                case GOM_Linking_Style.Line:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts;
                    System.Drawing.PointF			startPt, endPt;

                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgPts[0].X = endPt.X;
                    rgPts[0].Y = endPt.Y;
                    rgPts[1].X = x;
                    rgPts[1].Y = y;

                    matrix = new System.Drawing.Drawing2D.Matrix();
                    matrix.Translate(-startPt.X, -startPt.Y);
                    matrix.TransformPoints(rgPts);

                    float angle = (float)(System.Math.Atan2(endPt.Y - startPt.Y, endPt.X - startPt.X) / System.Math.PI) * 180;

                    matrix.Reset();
                    matrix.Rotate(-angle);
                    matrix.TransformPoints(rgPts);

                    if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                    {
                        return true;
                    }

                    break;
                }
                case GOM_Linking_Style.Polyline:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts, rgAllPts;
                    System.Drawing.PointF			startPt, endPt;
                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

                    rgAllPts[0].X = startPt.X;
                    rgAllPts[0].Y = startPt.Y;
                    for(int i=0; i<m_keyPts.Count; i++)
                    {
                        rgAllPts[1+i].X = m_keyPts[i].x;
                        rgAllPts[1+i].Y = m_keyPts[i].y;
                    }
                    rgAllPts[rgAllPts.Length-1].X = endPt.X;
                    rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

                    for(int i=0; i<(rgAllPts.Length-1); i++)
                    {
                        rgPts[0].X = rgAllPts[i+1].X;
                        rgPts[0].Y = rgAllPts[i+1].Y;
                        rgPts[1].X = x;
                        rgPts[1].Y = y;

                        matrix = new System.Drawing.Drawing2D.Matrix();
                        matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                        matrix.TransformPoints(rgPts);

                        float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                        matrix.Reset();
                        matrix.Rotate(-angle);
                        matrix.TransformPoints(rgPts);

                        if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                        {
                            return true;
                        }
                    }

                    break;
                }
                case GOM_Linking_Style.Curve:
                {
                    break;
                }
                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown link style.");
                    break;
            }

            return false;
        }
Beispiel #46
0
        private static PointF GetUpperCorner( float rotation, float left, float top, float width, float height )
        {
            // BUG 1006: Need to account for rotation when determining bounds
            if( rotation != 0 ) {
                PointF[] pts = new PointF[4];
                pts[0] = new PointF( left, top );
                pts[1] = new PointF( left, top + height );
                pts[2] = new PointF( left + width, top );
                pts[3] = new PointF( left + width, top + height );

                // Rotate the points
                System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
                m.RotateAt( rotation, new PointF( left + width/2.0f, top + height/2.0f ) );
                m.TransformPoints( pts );

                return new PointF( Math.Min( Math.Min( Math.Min( pts[0].X, pts[1].X ), pts[2].X ), pts[3].X ),
                                   Math.Min( Math.Min( Math.Min( pts[0].Y, pts[1].Y ), pts[2].Y ), pts[3].Y ) );
            } else {
                return new PointF( left, top );
            }
        }
            public void TestMatrix2()
            {
                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);

                var at = new AffineCoordinateTransformation2D(mat);
                var atInv = at.Inverse();

                var p0 = new double[] { 50d, 50d };
                var pt = at.Transform(p0);
                at.Invert();
                var p1 = at.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
                var p2 = atInv.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);

                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF ptt = pts[0];
                System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
Beispiel #48
0
        /// <summary>
        /// Set the Rovio's position using linear interpolation.
        /// </summary>
        private void SetNewRovioPosition()
        {
            Vector2 oldP = new Vector2(picBoxRovio.Location.X, picBoxRovio.Location.Y);
            Vector2 newP = new Vector2(0, -1);

            // Find the angle of the Rovio on the perimeter of the arena.
            newP = Vector2.Transform(-Vector2.UnitY, Matrix.CreateRotationZ(MathHelper.ToRadians((float)robot.cumulativeAngle)));
            newP /= MathHelper.Max(Math.Abs(newP.X), Math.Abs(newP.Y));
            newP += Vector2.One;
            newP *= new Vector2(260, 300) * 0.5f;

            // Translate into the arena from the perimeter.
            using (matrix = new System.Drawing.Drawing2D.Matrix())
            {
                matrix.Translate((int)newP.X, (int)newP.Y);
                matrix.RotateAt((float)robot.cumulativeAngle, new DPoint(0, 0));
                matrix.Translate(0f, (float)(robot.GetWallDist() * 100));
                DPoint[] newPos = { new DPoint(0, 0) };
                matrix.TransformPoints(newPos);

                if (newPos[0].X < -400 || newPos[0].X > 600)
                    newPos[0] = new DPoint(-100, -100);

                // Compensate for the alcoves.
                if (newPos[0].X < 30 && (newPos[0].Y < 100 || newPos[0].Y > 200))
                    newPos[0].X += 30;
                else if (newP.X > 230 && (newPos[0].Y < 100 || newPos[0].Y > 200))
                    newPos[0].X -= 30;
                newP = Vector2.Lerp(oldP, new Vector2(newPos[0].X, newPos[0].Y), 0.1f);

                picBoxRovio.Location = new DPoint((int)newP.X, (int)newP.Y);
            }
        }
		public override bool CalculateCalloutLocation(out PointF location, out CoordinateSystem coordinateSystem)
		{
			if (this.Roi.Points.Count < 3 || string.IsNullOrEmpty(this.Callout.Text))
				base.Callout.Visible = false;
			else
				base.Callout.Visible = true;

			if (!base.Callout.Visible || _userMovedCallout)
				return base.CalculateCalloutLocation(out location, out coordinateSystem);

			SizeF calloutOffsetDestination = GetCalloutOffsetDestination();

			coordinateSystem = CoordinateSystem.Destination;
			base.AnnotationGraphic.CoordinateSystem = coordinateSystem;

			// first, move the callout by the same amount the vertex moved (if it moved at all).
			location = base.Callout.TextLocation + calloutOffsetDestination;

			PointF start = this.Roi.Points[0];
			PointF vertex = this.Roi.Points[1];
			PointF end = this.Roi.Points[2];

			base.AnnotationGraphic.ResetCoordinateSystem();

			double vectorAngle = -Vector.SubtendedAngle(start, vertex, end) / 2 + 180;

			PointF[] points = new PointF[] { start, end };

			using (Matrix rotation = new Matrix())
			{
				rotation.Rotate((float) vectorAngle);
				rotation.Translate(-vertex.X, -vertex.Y);
				rotation.TransformPoints(points);
			}

			float calloutMagnitude = new Vector3D(location.X - vertex.X, location.Y - vertex.Y, 0).Magnitude;

			Vector3D startVector = new Vector3D(points[0].X, points[0].Y, 0);
			if (FloatComparer.AreEqual(startVector.Magnitude, 0F, 0.01F))
				startVector = new Vector3D(-1, 0, 0);

			startVector = startVector / startVector.Magnitude * calloutMagnitude;

			location = new PointF(startVector.X + vertex.X, startVector.Y + vertex.Y);

			return true;
		}
Beispiel #50
0
        /// <summary>
        /// Check if this command can be selected and return true in case it can
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);
            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected
            //float tmpX = LocationInPixelsX * zoomLevel;
            //float tmpY = LocationInPixelsY * zoomLevel;
            //float w = widthInPixels; //** zoomLevel;
            //float h = heightInPixels; //* zoomLevel;
            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Beispiel #51
0
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix matrix, RectangleF r)
 {
     s_tempPtsF[0] = new PointF(r.Left, r.Top);
     s_tempPtsF[1] = new PointF(r.Right, r.Bottom);
     matrix.TransformPoints(s_tempPtsF);
     return MakeRectangle(s_tempPtsF[0], s_tempPtsF[1]);
 }
Beispiel #52
0
        /// <summary>
        /// Return cursor for command
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="zoomLevel"></param>
        /// <returns>null if coordinates are not fine</returns>
        public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);
            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected

            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return this.cursor;
            }
            else
            {
                return null;
            }
        }