rotate around button

  • Thread starter Thread starter Magic Gooddy
  • Start date Start date
Magic Gooddy said:
Hi!
How to rotate one button around another like Sun and Planet?
Sample, please!

I suppose manipulating the location with a loop would do it. Just be sure to
watch the "bring to front" property.
 
How to rotate one button around another like Sun and Planet?
Sample, please!

I don't have a sample, but I can suggest a direction. You just need to use a
little trigonometry to calculate the x and y coordinates that the revolving
button will need as you go from 0 to 360 degrees. Cosine will give you the x
and Sine will give you the y.
 
VB uses Radians, not degrees for all of its trig. Remeber
to convert from one to the other to make sure everthing
works out fine.

2PI radians = 360 degrees.

1Pi radians = 180 degrees.

The code below draws a second hand on a clock face
using trig and radians.

Private Sub DrawSeconds()

Dim x As Double
Dim y As Double
Dim x1, y1 As Double
Dim myPen As New Pen(Color.Black, 1)

Dim rads As Double = ((Second * 6) - 180) * (PI / 180)

x = Centre.X - (((FaceWidth / 2) - 10) * Sin(rads))
x1 = Centre.X - (10 * Sin(rads))
y = Centre.Y + (((FaceWidth / 2) - 10) * Cos(rads))
y1 = Centre.Y + (10 * Cos(rads))
g.DrawLine(myPen, CInt(x1), CInt(y1), CInt(x), CInt(y))

End Sub


Good luck.
 
Magic,

As Jason points out, everything is done in Radians. This isn't just a VB thing,
every app that uses trigonometry nowadays really uses Radians internally.

Now I hate to ask, but why do you want Buttons to do this? Would someone be
trying to click the thing?
What will be your trigger? Will it just revolve at a particular interval, say
using a timer? Or will it move based another event of some sort?
Do you need to deal with the fact that mathematically you will get a point, but
since the button has width and height, it won't appear to make a circle unless
you account for this and use the calculated center point of the button.

Gerald
 
Back
Top