title: Algorithm for creating a circular path around a center mass?
body: <p>I am attempting to <em>simply</em> make objects orbit around a center point, e.g.</p>
  
  <p><img src="https://i.stack.imgur.com/J3Qe0.png" alt="Orbiting Objects"></p>
  
  <p>The green and blue objects represent objects which should keep their distance to the center point, while rotating, based on an angle which I pass into method.</p>
  
  <p>I have attempted to create a function, in objective-c, but it doesn't work right without a static number. e.g. (It rotates around the center, but not from the true starting point or distance from the object.)</p>
  
  <pre><code>-(void) rotateGear: (UIImageView*) view heading:(int)heading
  {
      // int distanceX = 160 - view.frame.origin.x;
      // int distanceY = 240 - view.frame.origin.y;
  
      float x = 160 - view.image.size.width / 2 + (50 * cos(heading * (M_PI / 180)));
      float y = 240 - view.image.size.height / 2 + (50 * sin(heading * (M_PI / 180)));
      view.frame = CGRectMake(x, y, view.image.size.width, view.image.size.height);
  }
  </code></pre>
  
  <p>My <em>magic numbers</em> 160, and 240 are the center of the canvas in which I'm drawing the images onto.  50 is a static number (and the problem), which allows the function to work partially correctly -- without maintaining the starting poisition of the object or correct distance.  I don't know what to put here unfortunately.</p>
  
  <p><code>heading</code> is a parameter that passes in a degree, from 0 to 359.  It is calculated by a timer and increments outside of this class.</p>
  
  <p>Essentially what I would like to be able to drop any image onto my canvas, and based on the starting point of the image, it would rotate around the center of my circle.  This means, if I were to drop an image at Point <code>(10,10)</code>, the distance to the center of the circle would persist, using <code>(10,10)</code> as a starting point.  The object would rotate 360 degrees around the center, and reach it's original starting point.</p>
  
  <p>The expected result would be to pass for instance <code>(10,10)</code> into the method, based off of zero degrees, and get back out, (<code>15,25</code>) (not real) at 5 degrees.</p>
  
  <p>I know this is very simple (and this problem description is entirely overkill), but I'm going cross eyed trying to figure out where I'm hosing things up.  I don't care about what language examples you use, if any.  I'll be able to decipher your meanings.</p>
  
  <p><strong>Failure Update</strong></p>
  
  <p>I've gotten farther, but I still cannot get the right calculation.  My new code looks like the following: </p>
  
  <p><code>heading</code> is set to 1 degree.</p>
  
  <pre><code>-(void) rotateGear: (UIImageView*) view heading:(int)heading
  {
      float y1 = view.frame.origin.y + (view.frame.size.height/2); // 152
      float x1 = view.frame.origin.x + (view.frame.size.width/2); // 140.5
  
      float radius = sqrtf(powf(160 - x1 ,2.0f) + powf(240 - y1, 2.0f)); // 90.13
  
      // I know that I need to calculate 90.13 pixels from my center, at 1 degree.      
      float x = 160 + radius * (cos(heading * (M_PI / 180.0f))); // 250.12
      float y = 240 + radius * (sin(heading * (M_PI / 180.0f))); // 241.57
  
      // The numbers are very skewed.
      view.frame = CGRectMake(x, y, view.image.size.width, view.image.size.height);
  }
  </code></pre>
  
  <p>I'm getting results that are no where close to where the point should be.  The problem is with the assignment of x and y.  Where am I going wrong?</p>