Пример #1
0
        public static void DrawLine(Graphics g, float width, Vector2 a, Vector2 b, Color c)
        {
            System.Drawing.Drawing2D.GraphicsState s = g.Save();

            //g.DrawLine(Pens.DarkGreen, a, b);

            float angle = (float)(180.0f / Math.PI * Math.Atan2(b.Y - a.Y, b.X - a.X));
            Font  f     = new Font(FontFamily.GenericSansSerif, 80, FontStyle.Bold);

            g.TranslateTransform(a.X, a.Y);
            g.RotateTransform(angle);
            float length = LineMath.Length(a, b);

            Color transparent = Color.FromArgb(200, c.R, c.G, c.B);

            //Brush br = new System.Drawing.Drawing2D.HatchBrush (System.Drawing.Drawing2D.HatchStyle.Sphere, Color.FromArgb(128, 100, 50, 25), Color.FromArgb(0, 0, 0, 0));
            Brush br = new SolidBrush(transparent);

            g.FillRectangle(br, new RectangleF(0, -width / 2, length, width));

            //g.DrawArc(Pens.Black, new RectangleF(-width / 2, -width / 2, width, width), 90, 180);
            g.FillEllipse(Brushes.White, new RectangleF(-width / 2, -width / 2, width, width));
            g.DrawEllipse(Pens.Black, new RectangleF(-width / 2, -width / 2, width, width));
            //g.DrawLine(Pens.Orange, new PointF(0, width / 2.0f), new PointF(length, width / 2.0f));
            //g.DrawLine(Pens.Orange, new PointF(0, -width / 2.0f), new PointF(length, -width / 2.0f));
            //g.TranslateTransform(p2.X - p1.X, p2.Y - p1.Y);

            g.TranslateTransform(length, 0);
            //g.DrawArc(Pens.Black, new RectangleF(-width / 2, -width / 2, width, width), 270, 180);
            g.FillEllipse(Brushes.White, new RectangleF(-width / 2, -width / 2, width, width));
            g.DrawEllipse(Pens.Black, new RectangleF(-width / 2, -width / 2, width, width));

            g.Restore(s);
        }
Пример #2
0
        public static float DistanceTo(Vector2 line1, Vector2 line2, Vector2 a)
        {
            float r = Math.Min(Length(line1, a), Length(line2, a));

            float length = LineMath.Length(line1, line2);

            if (length == 0)
            {
                return(r);
            }

            Vector2 n  = LineMath.Scale(LineMath.Sub(line1, line2), 1.0f / length);
            float   d1 = LineMath.Mult(line1, n) - LineMath.Mult(a, n);

            n = new Vector2(-n.Y, n.X);
            float d2 = LineMath.Mult(line1, n) - LineMath.Mult(a, n);

            if (d1 <= length && d1 >= 0)
            {
                return(Math.Min(Math.Abs(d2), r));
            }
            return(r);
        }