# Thread: [RESOLVED] Move point around circle path

1. ## [RESOLVED] Move point around circle path

Hi!

Say please, how possible moving shape to specific degree of another shape?
I know only radius of big circle path, and degree which i'm needed to move the shape.

My code is:
Code:
```    'get radius of path shape

For i = 1 To 360 Step 15
rad = i * (3.14159265358979 / 180)

'move point to path direction for each 15 degrees
Next```
but my point move stepper and not properly.
My sample in attach. I want move point by big circle path. Who can help please?
pathforpoint.zip

2. ## Re: Move point around circle path

You need to offset your computed distance from the center of the shape.
It is easiest to compute the center of the shape at the beginning, and use it.
So, I computer the center (CenterX, CenterY), and use the computed end point of the radius at the specified angle you provided and subtract -4.5 in X and Y to offset to the point's center, approximately.
Code:
```Sub DrawToPath()

Dim i As Integer
Dim CenterX As Single, CenterY As Single

'set shapes to base coordinates
ActiveSheet.Shapes("path").Left = 36.75
ActiveSheet.Shapes("path").Top = 59.25

ActiveSheet.Shapes("point").Left = 139.1243
ActiveSheet.Shapes("point").Top = 54.10535

For i = 0 To 360 Step 15
rad = i * (3.14159265358979 / 180)

'mone point to path direction for each 15 degrees
Next

End Sub```

3. ## Re: Move point around circle path

I put a short delay in so you can see the point animate around the circle.
Originally using Application.Wait, but that has a minimum resolution of 1 second, and hangs the application while waiting.
Then, just used a loop using Timer, which probably has a resolution of 64 times per second so a delay of 2/64 should give you a pretty steady 32hz animation.
Code:
```    For i = 0 To 360 Step 15
rad = i * (3.14159265358979 / 180)

'mone point to path direction for each 15 degrees

'  Application.Wait (Now + TimeValue("0:00:01"))
Dim endTime As Single
endTime = Timer + (2 / 64)
Do While Timer < endTime: DoEvents: Loop
Next```
p.s. Just changed the code to compute the point offset, depending on its size, rather than use a hardcoded -4.5
Code:
```Sub DrawToPath()

Dim i As Integer
Dim CenterX As Single, CenterY As Single
Dim pointOffset As Single

'set shapes to base coordinates
ActiveSheet.Shapes("path").Left = 36.75
ActiveSheet.Shapes("path").Top = 59.25

ActiveSheet.Shapes("point").Left = 139.1243
ActiveSheet.Shapes("point").Top = 54.10535

pointOffset = -(ActiveSheet.Shapes("point").Width / 2)

For i = 0 To 360 Step 15
rad = i * (3.14159265358979 / 180)

'mone point to path direction for each 15 degrees
Dim endTime As Single
endTime = Timer + (2 / 64)
Do While Timer < endTime: DoEvents: Loop
Next

End Sub```

4. ## Re: Move point around circle path

Oh, cool! Mega merci! Thats what i'm wanted.

5. ## Re: Move point around circle path

By default, the angles and rotation are based on the common mathematical sense, i.e. 0 degrees is to the right along the X axis, and positive angles rotate counter-clockwise around the center. But since the Y axis is Positive going down in the window, the rotation ends up being clockwise, even though 90 is still along the X-axis.

If you prefer 0 degrees to be toward the top of the Y axis, and rotating clockwise, like a compass, you have two choices (there are more than two choices, but these are the two I generally choose from).
Keep the calculations as they are, but subtract 90 degrees from the input, or
you swap the sin and cos functions, negating the cos, as shown below.
Code:
```        ActiveSheet.Shapes("point").Left = pointOffset + CenterX + bigCircleRadius * Sin(rad)

6. ## Re: [RESOLVED] Move point around circle path

Also, i'm experimented with rotating pivot coordinates of point.
equation of transfer of a point on an angle
but also stepped drawing instead linear.

#### 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