I am creating a simple orbit system, where you have the earth and the sun, created based on a UserControl
, the problem is that I do not know why the angle gets wacky when placing an angle in the Angle
property. The control is this:
Andhere'syourcode:
PublicPropertyAngleAsIntegerPrivateSubOrbit_Paint(senderAsObject,eAsPaintEventArgs)HandlesMe.PaintDimg_AsGraphics=e.Graphicsg_.SmoothingMode=SmoothingMode.HighQualityDimpAsNewPen(Color.White,1)DimmyRect=Me.ClientRectangleDimoriginAsNewPoint(myRect.Width/2,myRect.Height/2)g_.DrawEllipse(p,myRect)Dimr=myRect.Height/2Dima=AngleDimnx=r*Cos(a)+origin.XDimny=r*Sin(a)+origin.YDimnpAsNewPoint(nx,ny)Dimax_earthAsNewPoint(np.X-5,np.Y-5)Dimax_sunAsNewPoint(origin.X-5,origin.Y-5)g_.DrawLine(NewPen(Color.Gray,1),origin,np)g_.FillEllipse(NewSolidBrush(Color.DeepSkyBlue),NewRectangle(ax_earth,NewSize(5,5)))g_.FillEllipse(NewSolidBrush(Color.Gold),NewRectangle(ax_sun,NewSize(10,10)))EndSub
Iused polar coordinates to calculate the x, y point of where the planet will be earth, the formulas are as follows:
risthehorizontalsizedividedbytwo.θisdefinedbytheAngle
Theproblem
Evenbeauty,whenforexampleIputinthepropertyAngle
90,thecorrectthingwastobeintheperfecthorizontalhalf,butthatwaswhatitgave:
SoItried120:
IthinktheproblemisintheDima=Angle
line,butIhonestlydonotknowtheformulatosolvethis.AsIleavetheperfectangle,moreorlesslikethis[?]: