Hi,
I'm assuming you want this formula so that you can animate text
rotating around a circle in Macromedia ActionScript. As I understand,
you want the baseline of the text to be tangent to the circle, no
matter the position of the text on the circle. (ie. so if the text is
at the 180 degree position on the circle, the text would be upside
down) You are correct in assessing that the height of the character
does not matter.
Here is some pseudo-code that will achieve what you are after, using
your letter "B" example. It is written VB-style, but I believe it is
very straightforward and you should have no problem switching it to
ActionScript.
You can read a more in-depth explanation of the circle algorithm in
Denthor's VGA Graphics Trainer.
(http://www.gamedev.net/reference/articles/article349.asp)
If you need any clarification, do not hesitate to ask.
Good luck with your project,
-Spot
Framerate = 30 // frames per second (set to 30 fps)
DeltaTime = 1 / Framerate // seconds per frame
AngleOfText = 0.0 // position of letter in radians, start
at 0
RotationsPerSecond = 1 // number of rotations around the circle
per second
// (set to one rotation per
second)
// animate forever
While (True)
// calculate number of radians to move each frame
// note: if you want a dynamic framerate, just update DeltaTime
with the
// percentage of a second since the last frame
DeltaText = (2 * PI) * RotationsPerSecond * DeltaTime
// update angle each frame
AngleOfText += DeltaText
If AngleOfText > (2 * PI) Then
AngleOfText = AngleOfText - (2 * PI)
End If
// calculate position... x and y represent the center of baseline
of the text, where
// the baseline is the imaginary line that runs along the bottom of
the character
// that is also tangent to the circle
PositionX = CenterOfCircleX + Round(RadiusOfCircle *
Cos(AngleOfText))
PositionY = CenterOfCircleY + Round(RadiusOfCircle *
Sin(AngleOfText))
// draw the letter... note, the angle of the characters baseline is
the same
// as the rotation position angle along the circle i.e.
AngleOfText is the
// amount you want to rotate the character around its own axis when
you
// draw it. if your text rendering function wants the angle in
degrees instead
// of radians, simply multiple AngleOfText by 57.29577951
MyFunctionThatDrawsText("B", PositionX, PositionY, AngleOfText)
Wend |
Clarification of Answer by
spot_tippybuttons-ga
on
06 Feb 2003 03:09 PST
Aargh! I apologize that the posting tool wrapped unexpectedly when I
posted the text. Here it is again, hopefully a little easier to read!
-Spot
// frames per second (set to 30 fps)
Framerate = 30
// seconds per frame
DeltaTime = 1 / Framerate
// position of letter in radians, start at 0
AngleOfText = 0.0
// number of rotations around the circle per second
// (set to one rotation per second)
RotationsPerSecond = 1
// animate forever
While (True)
// calculate number of radians to move each frame
// note: if you want a dynamic framerate, just update
// DeltaTime with the percentage of a second since
// the last frame
DeltaText = (2 * PI) * RotationsPerSecond * DeltaTime
// update angle each frame
AngleOfText += DeltaText
If AngleOfText > (2 * PI) Then
AngleOfText = AngleOfText - (2 * PI)
End If
// calculate position... x and y represent the center
// of baseline of the text, where the baseline is the
// imaginary line that runs along the bottom of the
// character that is also tangent to the circle
PositionX = CenterOfCircleX +
Round(RadiusOfCircle * Cos(AngleOfText))
PositionY = CenterOfCircleY +
Round(RadiusOfCircle * Sin(AngleOfText))
// draw the letter... note, the angle of the characters
// baseline is the same as the rotation position angle
// along the circle i.e. AngleOfText is the amount you
// want to rotate the character around its own axis when
// you draw it. if your text rendering function wants the
// angle in degrees instead of radians, simply multiple
// AngleOfText by 57.29577951
MyFunctionThatDrawsText("B", PositionX, PositionY, AngleOfText)
Wend
|