2

Ok it's beyond the scope of this programming exercise, but I want to create a loop that will allow me to input any number of characters and the loop gets each character in the string and places it at regular intervals at specific coordinates in a circular pattern... This I'm sure will require Trigonometry which I'm not really too familiar with yet, but I can tell you that the center coordinates and circle radius will already be predetermined, so based on the Radius of the circle and coordinates how would I make an algorithm that can calculate the coordinates...think of this like a clock and your wanting to place 12 numbers in intervals around the outside of the circle...If you need any specifics ask me and I'll let you know

The reason I'm wanting to do this is so that anytime I wish to place text in such a way in my program I can import a piece of code that will only need the string and it will do the rest.

Edit: This loop should be able to calculate the position based on the number and size of circle

Edit: If anyone even knows a formula that exists for such an operation then I would be happy to study it for myself

  • Basically what I mean by string is a series of letters like "abcdefg" and a loop you don't really need to know much about aside from say if there are 12 letters then it will place a letter at a specific coordinate and then grab another and repeat so the algorithm needs to be repeatable so that it can be used 12 times with all 12 letters and everyone still gets placed in it's correct position – John Conner Jul 13 '14 at 11:40
  • Also the size of the circle and the angle with be determined based on the size of the string – John Conner Jul 13 '14 at 11:53

2 Answers2

2

Let us assume that the center has Euclidian coordinates $(x_C,y_C)$ and the circle has radius $R$. If your string has $N$ characters $a_1,\dots,a_N$ then the $k$-th character will be placed at $$ x_k = x_C + R\cos\left(-\frac{2k\pi}{N} + \phi\right), \quad y_k = y_C + R\sin\left(-\frac{2k\pi}{N} + \phi\right). $$ The real number $\phi$ is an offset your are free to choose (it allows you to change the "starting point"). Notice that the '-' sign comes from the fact that you probably want to place your letters clockwisely.

Siméon
  • 10,664
  • 1
  • 21
  • 54
  • Thanks @Siméon, that puts it into perspective – John Conner Jul 13 '14 at 12:08
  • 1
    Note that in a computer-graphical context, the $y$-axis frequently has a reverse orientation, so the OP may want to use $$y_k =y_C-R\sin(\phi-2\pi k/N)$$ instead. Other than that, this is quite close to what I was about to post, so I'll just upvote your solution instead of posting a near-duplicate. – MPW Jul 13 '14 at 12:10
  • @MPW: good remark (+1)! – Siméon Jul 13 '14 at 12:10
  • Thanks again, I got it now :D, I'm working on getting the loop going but I have a working algorithm now :) – John Conner Jul 13 '14 at 12:42
0

Suppose there are $n$ letters in the string and there is a letter exactly at the right of the circle which has radius $r$ and center $(x,y)$. Now, we want the $n$ letters to be at the following positions: for $\theta_i=\frac in 2\pi$ the positions are $$ (x+r \cos\theta_i,y+r \sin\theta_i) $$

Ragnar
  • 6,233