Google Answers Logo
View Question
 
Q: Graphics ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: Graphics
Category: Computers > Algorithms
Asked by: edju-ga
List Price: $20.00
Posted: 17 Jan 2003 12:18 PST
Expires: 16 Feb 2003 12:18 PST
Question ID: 144842
Rotate text characters around a circle so that all characters are
perpendicular to the arc of the circle and all rotate at a given
speed.

Request for Question Clarification by seizer-ga on 17 Jan 2003 12:36 PST
Hi there edju.

Your question is not actually a question! What do you need from the
researchers? Programming code? If so, which language? The more details
you're able to give, the better we'll be able to assist you.

Regards,

--seizer-ga

Clarification of Question by edju-ga on 17 Jan 2003 13:57 PST
This is a question. Program code in VB 6, VBA or Macromedia
ActionScript is wanted. Mostly in Macromedia ActionScript.

I cannot draw in this window; however, if you have a 3-inch, diameter
circle and you place the lower case letter b on it so that the
ascender on the b is perpendicular to the circle at the left-hand side
of the circle and at 90 degrees to the circle and you move it, say in
the direction towards the top of the circle by about 1/2", what would
the degrees be then on the b and as it moves in a smooth motion around
the circle, what function could be applied in the degrees of change
needed in the algorithm? The b may be about 3/8" high, relative to the
size of the circle, although the size of the character doesn't matter
in this question.
Answer  
Subject: Re: Graphics
Answered By: spot_tippybuttons-ga on 06 Feb 2003 03:03 PST
Rated:5 out of 5 stars
 
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
edju-ga rated this answer:5 out of 5 stars
Will come back to tip, but answer and question is correct about the
letter B becoming upside down at 180 degees.

Comments  
Subject: Re: Graphics
From: jeanluis-ga on 17 Jan 2003 15:35 PST
 
It sounds like what you need is the parametric equation for a sphere
x = r sin(theta)cos(phi)
y = r sin(theta)sin(phi)
z = r cos(theta)

Where r is the radius of the sphere, theta is the angle from the z
axis (0 <= theta <= pi), and phi the angle from the x axis (0 <= phi
<= 2pi). You could use these equations to estimate the angle you
seek...

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy