This are used to show how to generate an oval.
The moon ' s orbit around the sun is an oval.
Nobelium controlling sing system;using system.windows.forms;using system.drawing;using system.collections.generic;class haha:form{Haha () {WindowState = formwindowstate.maximized; Paint + = draw; Timer T = new timer (); T.tick + = delegate {Invalidate (); }; Init (); T.interval = 200; T.start (); Activated + = delegate {T.start (); }; SizeChanged + = delegate {if (WindowState = = formwindowstate.minimized) t.stop (); }; } const int period=100; int now=0; Bitmap[] Bit=new Bitmap[period]; void init () {double the=math.pi*2/period; linkedlist<point> mark = new Linkedlist<point> (); var p = new Pen (new SolidBrush (Color.tomato), 1); for (int i = 0; i < bit. Length; i++) {Bit[i] = new Bitmap (200,200); var g = Graphics.fromimage (Bit[i]); int R = Math.min (Bit[i]. Width, Bit[i]. Height) >> 1; int x = Bit[i]. Width >> 1; int y = bit[i]. Height >> 1; G.drawellipse (P, X-r, Y-r, R << 1, r << 1); int RR = R >> 1; Double xx = x + RR * MATH.COS (the * i); Double yy = y + RR * Math.sin (the * i); G.drawellipse (P, (float) (XX-RR), (float) (YY-RR), RR << 1, RR << 1); Double r = RR * 0.5; Double xxx = xx + R * Math.Cos (-the * i); Double yyy = yy + R * Math.sin (-the * i); Mark. AddLast (new Point ((int) xxx, (int) yyy)); G.drawellipse (P, (float) (xxx-r), (float) (yyy-r), (float) R * 2, (float) R * 2); foreach (Var point in Mark) {G.fillellipse (new SolidBrush (Color.tomato), point. X, point. Y, 2, 2); } g.drawline (P, (float) xxx, (float) yyy, (float) xx, (float) yy); G.drawline (P, (float) xx, (float) yy, (float) x, (float) y); } } void Draw (Object O,painteventargs e) {now = (now + 1)% period; int w = math.min (Clientsize.width, clientsize.height); E.graphics.drawimage (BIT[NOW],0,0,W,W); } static void Main () {Application.Run (New Haha ()); }}
The oval rotates around its own corner.
1 usingSystem;2 usingSystem.Windows.Forms;3 usingSystem.Drawing;4 classHaha:form5 {6 Haha ()7 {8Text ="Elliptical Focus Polar coordinate equation: clockwise rotation minus rotation angle, counterclockwise rotation plus rotation angle";9Paint + =Draw;TenWindowState =formwindowstate.maximized; One } A DoubleA, B, W, H; - DoubleC, E, K; - DoubleFxDoubleThe,DoublePhi) the { - returnK/(1+ E * Math.Cos (the-phi)) *Math.Cos (the); - } - DoubleFyDoubleThe,DoublePhi) + { - returnK/(1+ E * Math.Cos (the-phi)) *Math.sin (the); + } A Point Mix, Miy, corner; at DoubleMinX (DoublePhi) - { - DoubleL = Math.PI/2, r = Math.PI/2*3; - while(R-l > 1e-8) - { - DoubleD = (r-l)/3; in DoubleLM = L +D; - DoubleRM = R-D; to if(FX (LM, PHI) > FX (rm, phi)) L =LM; + ElseR =RM; - } theMix. X = (int) FX (L, PHI); *Miy. Y = (int) FY (l, phi); $ returnFX (L, PHI);Panax Notoginseng } - DoubleMiny (DoublePhi) the { + DoubleL =-math.pi, r =0; A while(R-l > 1e-8) the { + DoubleD = (r-l)/3; - DoubleLM = L +D; $ DoubleRM = R-D; $ if(FY (LM, phi) > FY (rm, phi)) L =LM; - ElseR =RM; - } theMiy. X = (int) FX (L, PHI); -Miy. Y = (int) FY (l, phi);Wuyi returnfy (L, phi); the } - voidDrawObjecto, PaintEventArgs pe) Wu { - DoublePhi = math.pi* -/ the; AboutText =""+ Phi/math.pi * the; $ PE. Graphics.clear (color.wheat); - varPen =NewPen (NewSolidBrush (Color.aqua),3); - DoubleThe =2* Math.PI/ the; -A=math.min (clientsize.width,clientsize.height) >>2; Ab=0.618*A; +k=b*b/A; theC=MATH.SQRT (a*a-b*b); -e=c/A; $ intCenterX = Clientsize.width >>1; the intCenterY = Clientsize.height >>1; the for(Doublei =0; i<2* MATH.PI; i + =The ) the { the Doublex=k/(1+e*math.cos (I-phi)) *Math.Cos (i); - Doubley = k/(1+ E * Math.Cos (i-phi)) *Math.sin (i); inPe. Graphics.FillEllipse (NewSolidBrush (Color.tomato), (int) (X+centerx), (int) (Y+centery),2,2); the } thePe. Graphics.FillEllipse (NewSolidBrush (Color.tomato), CenterX, CenterY,8,8); About MinX (PHI); the Miny (PHI); theCorner. x=mix. X; theCorner. y=Miy. Y; +Mix. X + =CenterX; -Mix. Y + =CenterY; theMiy. X + =CenterX;BayiMiy. Y + =CenterY; theCorner. X + =CenterX; theCorner. Y + =CenterY; -Pen. Color =Color.Black; - PE. Graphics.drawline (pen, mix, corner); thePen. Color =Color.Blue; the PE. Graphics.drawline (pen, Miy, corner); thePe. Graphics.FillEllipse (NewSolidBrush (Color.Blue), Miy. X, Miy. Y8,8); the } - Static voidMain () the { theApplication.Run (NewHaha ()); the }94}
C # Rotating Oval