title: How can I constrain an object's movement inside an ellipse?
body: <h2>The scenario</h2>
  
  <p>I have several objects in a grid. I translate them inside their manipulation delta event. The objects appear stuck under the user's pointer. It works, and looks something like this:</p>
  
  <pre><code>ellipse.ManipulationDelta += (s, e) =&gt;
  {
      var transform = ellipse.RenderTransform as CompositeTransform;
      transform.TranslateX = e.Cumulative.Translation.X;
      transform.TranslateY = e.Cumulative.Translation.Y;
  }
  </code></pre>
  
  <p>Every movable object has an elliptical boundary outside of which the object should not be dragged. This value is simple to calculate. Something like this:</p>
  
  <pre><code>ellipse.ManipulationDelta += (s, e) =&gt;
  {
      var boundary = new Ellipse { Height = 50, Width = 100 };
  
      var transform = ellipse.RenderTransform as CompositeTransform;
      transform.TranslateX = e.Cumulative.Translation.X;
      transform.TranslateY = e.Cumulative.Translation.Y;
  };
  </code></pre>
  
  <h2>The requirement</h2>
  
  <p>I would like to implement some type of logic that would not translate the element if the requested point is outside the elliptical boundary. </p>
  
  <p><a href="https://i.stack.imgur.com/r4xWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r4xWR.png" alt="enter image description here"></a></p>
  
  <p>Something, perhaps like this:</p>
  
  <pre><code>ellipse.ManipulationDelta += (s, e) =&gt;
  {
      var boundary = new Ellipse { Height = 50, Width = 100 };
      var point = DeterminePoint(boundary, e.Cumulative.Translation);
  
      var transform = ellipse.RenderTransform as CompositeTransform;
      transform.TranslateX = point.X;
      transform.TranslateY = point.Y;
  };
  
  Point DeterminePoint(Ellipse boundary, Point target) { /* TODO */ }
  </code></pre>
  
  <p>I can easily write the code to constrain the logic to a rectangle. But a rectangle is not the requirement, an ellipse is. It's the <code>TODO</code> section in the code above that is the heart of this question.</p>
  
  <p>Thank you, in advance. </p>