# Thread: [RESOLVED] Orbit a PictureBox around another PictureBox...

1. ## [RESOLVED] Orbit a PictureBox around another PictureBox...

I've found code that DRAWS circles and makes them orbit each other, but I can't for the life of me figure out how to implement this using two PictureBox controls (one orbiting around the other).

2. ## Re: Orbit a PictureBox around another PictureBox...

The pictureboxes won't be able to rotate, although you could rotate their contents assuming the drawing inside is small enough not to be clipped by the rotation.

If you just want to orbit to pictureboxes, and not need to rotate them, then just use the circle code, which I assume is calculating the center of two circles. The two points would be the center of the pictureboxes (half width and half height).
You would then offset the position by that half width, and half height, to locate the pictureboxes left,top corner so that the center of the box is at the center point calculated.

Here's an example just written from scratch. Just need two pictureboxes, relatively small, perhaps 40 pixels or so in size and a timer control.
Code:
```Option Explicit
Dim cx1 As Single, cx2 As Single
Dim cy1 As Single, cy2 As Single
Dim fcx As Single, fcy As Single
Dim orbitDist As Single
Dim orbitX As Single, orbitY As Single

Dim Ang As Double
Dim PI As Double

'atn(1) corresponds to 45 degrees (in radians)
'PI corresponds to 180 degrees in Radians
'so multiply 45 * 4 = 180  Atn(1) * 4 = PI
PI = Atn(1) * 4

ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
cx1 = Picture1.Width / 2
cy1 = Picture1.Height / 2
cx2 = Picture2.Width / 2
cy2 = Picture2.Height / 2
fcx = ScaleWidth / 2
fcy = ScaleHeight / 2
If fcx > fcy Then
orbitDist = fcy / 2
Else
orbitDist = fcx / 2
End If
Picture1.Left = fcx - cx1  'Put Picture1 in the center of the form
Picture1.Top = fcy - cy1
Timer1.Interval = 10
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Ang = Ang + 0.01
End If
orbitX = fcx + orbitDist * Sin(Ang)
orbitY = fcy + orbitDist * Cos(Ang)
Picture2.Move orbitX - cx2, orbitY - cy2
End Sub```

3. ## Re: Orbit a PictureBox around another PictureBox...

Thank you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured