public override double ComputeArea() { return(Math.PI * Axis1.ComputeLength() / 2 * Axis2.ComputeLength() / 2); }
//Create an ellipse given a binding rectangle. public Ellipse(string _name, string _color, Rectangle _BindingRectangle) : base(_name, _color) { BindingRectangle = _BindingRectangle; Line Diagonal = new Line(_name + "'s Diagonal", _color, BindingRectangle.myPoints[0], BindingRectangle.myPoints[2]); Point CenterOfDiagonal = new Point("null", "null", ((Diagonal.myPoints[0].X + Diagonal.myPoints[1].X) / 2), ((Diagonal.myPoints[0].Y + Diagonal.myPoints[1].Y) / 2)); Point CenterOfRectangleEdge1 = new Point("null", "null", ((BindingRectangle.myPoints[0].X + BindingRectangle.myPoints[1].X) / 2), ((BindingRectangle.myPoints[0].Y + BindingRectangle.myPoints[1].Y) / 2)); Point CenterOfRectangleEdge2 = new Point("null", "null", ((BindingRectangle.myPoints[1].X + BindingRectangle.myPoints[2].X) / 2), ((BindingRectangle.myPoints[1].Y + BindingRectangle.myPoints[2].Y) / 2)); Point CenterOfRectangleEdge3 = new Point("null", "null", ((BindingRectangle.myPoints[2].X + BindingRectangle.myPoints[3].X) / 2), ((BindingRectangle.myPoints[2].Y + BindingRectangle.myPoints[3].Y) / 2)); Point CenterOfRectangleEdge4 = new Point("null", "null", ((BindingRectangle.myPoints[3].X + BindingRectangle.myPoints[0].X) / 2), ((BindingRectangle.myPoints[3].Y + BindingRectangle.myPoints[0].Y) / 2)); Line _Axis1 = new Line(_name + "'s _Axis1", _color, CenterOfRectangleEdge1, CenterOfRectangleEdge3); Line _Axis2 = new Line(_name + "'s _Axis2", _color, CenterOfRectangleEdge2, CenterOfRectangleEdge4); Center = CenterOfDiagonal; Vertex1 = CenterOfRectangleEdge1; Vertex2 = CenterOfRectangleEdge2; Vertex3 = CenterOfRectangleEdge3; Vertex4 = CenterOfRectangleEdge4; Axis1 = _Axis1; Axis2 = _Axis2; if (Axis1.ComputeLength() > Axis2.ComputeLength()) { //Axis1 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(_name + "'s Foci2", _color, CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(_name + "'s Foci2", _color, Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } else { //Axis2 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(_name + "'s Foci2", _color, CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Focis are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(_name + "'s Foci2", _color, Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } }
//Create an ellipse given a binding rectangle. public Ellipse(Rectangle _BindingRectangle) { BindingRectangle = _BindingRectangle; Line Diagonal = new Line(BindingRectangle.Vertex1, BindingRectangle.Vertex3); Point CenterOfDiagonal = new Point(((Diagonal.Point1.X + Diagonal.Point2.X) / 2), ((Diagonal.Point1.Y + Diagonal.Point2.Y) / 2)); Point CenterOfRectangleEdge1 = new Point(((BindingRectangle.Vertex1.X + BindingRectangle.Vertex2.X) / 2), ((BindingRectangle.Vertex1.Y + BindingRectangle.Vertex2.Y) / 2)); Point CenterOfRectangleEdge2 = new Point(((BindingRectangle.Vertex2.X + BindingRectangle.Vertex3.X) / 2), ((BindingRectangle.Vertex2.Y + BindingRectangle.Vertex3.Y) / 2)); Point CenterOfRectangleEdge3 = new Point(((BindingRectangle.Vertex3.X + BindingRectangle.Vertex4.X) / 2), ((BindingRectangle.Vertex3.Y + BindingRectangle.Vertex4.Y) / 2)); Point CenterOfRectangleEdge4 = new Point(((BindingRectangle.Vertex4.X + BindingRectangle.Vertex1.X) / 2), ((BindingRectangle.Vertex4.Y + BindingRectangle.Vertex1.Y) / 2)); Line _Axis1 = new Line(CenterOfRectangleEdge1, CenterOfRectangleEdge3); Line _Axis2 = new Line(CenterOfRectangleEdge2, CenterOfRectangleEdge4); Center = CenterOfDiagonal; Vertex1 = CenterOfRectangleEdge1; Vertex2 = CenterOfRectangleEdge2; Vertex3 = CenterOfRectangleEdge3; Vertex4 = CenterOfRectangleEdge4; Axis1 = _Axis1; Axis2 = _Axis2; if (Axis1.ComputeLength() > Axis2.ComputeLength()) { //Axis1 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } else { //Axis2 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Focis are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } }