示例#1
0
 public void AddFigure(Figure f)
 {
     this.FigureList.Add(f);
 }
示例#2
0
        public bool Cross(Figure f2)
        {
            string n1       = "Cylinder Torus Sphere";
            double distance = Math.Sqrt(Math.Pow(f2.X - this.X, 2) + Math.Pow(f2.Y - this.Y, 2));

            if (n1.Contains(this.GetType().Name) && n1.Contains(f2.GetType().Name))
            {
                Figure3D k1 = (Figure3D)this;
                Figure3D k2 = (Figure3D)f2;

                return(k1.Cross(k2));
            }

            #region 2D
            else if (Math.Round(distance) == 0 && this.Square() == f2.Square())
            {
                return(true);
            }

            else if (this.Radius >= f2.Radius)
            {
                double r = Math.Round(Math.Sqrt(this.Radius * this.Radius - (this.Square() / Pi)));

                if (this.X + r >= f2.X + f2.Radius && this.X - r <= f2.X - f2.Radius &&
                    this.Y + r >= f2.Y + f2.Radius && this.Y - r <= f2.Y - f2.Radius)
                {
                    return(false);
                }
                else if ((this.X + this.Radius >= f2.X + f2.Radius && this.X - this.Radius <= f2.X - f2.Radius &&
                          this.Y + this.Radius >= f2.Y + f2.Radius && this.Y - this.Radius <= f2.Y - f2.Radius) && this.GetType().Name == "Circle")
                {
                    return(false);
                }

                else if (distance < this.Radius + f2.Radius)
                {
                    return(true);
                }
            }

            else if (this.Radius <= f2.Radius)
            {
                double r = Math.Sqrt(f2.Radius * f2.Radius - (f2.Square() / Pi));

                if (f2.X + r >= this.X + this.Radius && f2.X - r <= this.X - this.Radius &&
                    f2.Y + r >= this.Y + this.Radius && f2.Y - r <= this.Y - this.Radius)
                {
                    return(false);
                }
                else if ((f2.X + f2.Radius >= this.X + this.Radius && f2.X - f2.Radius <= this.X - this.Radius &&
                          f2.Y + f2.Radius >= this.Y + this.Radius && f2.Y - f2.Radius <= this.Y - this.Radius) && this.GetType().Name == "Circle")
                {
                    return(false);
                }
                else if (distance < this.Radius + f2.Radius)
                {
                    return(true);
                }
            }

            else if (distance < this.Radius + f2.Radius)
            {
                return(true);
            }
            #endregion

            return(false);
        }