Esempio n. 1
0
 protected void UpdateDiagonal()
 {
     min = vert.First();
     max = vert.First();
     foreach (PointF t in vert)
     {
         if (t.X < min.X)
         {
             min.X = t.X;
         }
         if (t.Y < min.Y)
         {
             min.Y = t.Y;
         }
         if (t.X > max.X)
         {
             max.X = t.X;
         }
         if (t.Y > max.Y)
         {
             max.Y = t.Y;
         }
     }
     diagonal = new CSegment(min, max);
     center   = new PointF((min.X + max.X) / 2,
                           (min.Y + max.Y) / 2);
     r = Math.Sqrt((min.X - max.X) * (min.X - max.X) +
                   (min.Y - max.Y) * (min.Y - max.Y)) / 2;
 }
Esempio n. 2
0
 public Polygon()
 {
     vert     = new List <PointF>();
     min      = new PointF();
     max      = new PointF();
     diagonal = new CSegment(min, max);
     center   = new PointF();
 }
Esempio n. 3
0
 public CSegment(CSegment seg)
 {
     _a     = seg._a;
     _b     = seg._b;
     _angle = seg._angle;
     _color = seg.color;
     center = seg.center;
     r      = seg.r;
 }
Esempio n. 4
0
 public Polygon(Polygon pol)
 {
     vert     = pol.vert;
     min      = pol.min;
     max      = pol.max;
     diagonal = pol.diagonal;
     _color   = pol.color;
     center   = pol.center;
     r        = pol.r;
 }
Esempio n. 5
0
        public override bool Contains(PointF p)
        {
            PointF   end   = new PointF(p.X + 99999, p.Y);
            CSegment ray   = new CSegment(p, end);
            PointF   prev  = vert.Last();
            int      count = 0;

            foreach (PointF i in vert)
            {
                CSegment c     = new CSegment(prev, i);
                PointF   isctn = ray.Intersects(c);
                if (c.Contains(isctn) && ray.Contains(isctn))
                {
                    ++count;
                }
                prev = i;
            }
            return(count % 2 == 1);
        }
Esempio n. 6
0
        public PointF Intersects(CSegment a)
        {
            double k1  = Math.Tan(a.Angle);
            double k2  = Math.Tan(this.Angle);
            double m1  = a.A.Y - k1 * a.A.X;
            double m2  = this.A.Y - k2 * this.A.X;
            PointF ans = new PointF(-1, -1);

            try
            {
                ans.X = (float)((m2 - m1) / (k1 - k2));
                ans.Y = (float)(k2 * ans.X + m2);
            }
            catch (DivideByZeroException)
            {
                ans.X = 99999;
                ans.Y = 99999;
            }
            return(ans);
        }