determine if a point is an an ellipse

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • illusion.admins@gmail.com

    determine if a point is an an ellipse

    I am trying to code something to tell me if a selected point is in a
    particular ellipse. For the ellipse I know how it was constructed
    (know the x,y, and width, height). But if I just check to see if the
    point is in the rectangle making up the ellipse wouldn't that possibly
    give me a false answer? Eg if the point is the upper left coordinate
    of the rectangle...thi s point is in the rectangle making up ellipse
    but NOT the ellipse itself.

    Thanks for and advice.
  • Peter Duniho

    #2
    Re: determine if a point is an an ellipse

    On Wed, 20 Feb 2008 12:47:07 -0800, <illusion.admin s@gmail.comwrot e:
    In the instance of what I am using the ellipse is actually a circle.
    Well, then the math is trivial. Even if you're using a square to define
    the circle, the center is just the average of the top left and bottom
    right corner point coordinates, the radius is half the width of the
    square, and a point is inside the circle if the distance from the center
    to the point is less than the radius.

    Pete

    Comment

    • Paul E Collins

      #3
      Re: determine if a point is an an ellipse

      <illusion.admin s@gmail.comwrot e:
      [find point inside a circle]
      This is really a maths question, not a programming question, but I have
      the C# code kicking around from a simple shape-based drawing application
      a couple of years ago. It's for circles only, not ellipses.

      public bool ContainsPoint(P oint centre, int radius, Point toTest)
      {
      // Is the point inside the circle? Sum the squares of the
      x-difference and
      // y-difference from the centre, square-root it, and compare with the
      radius.
      // (This is Pythagoras' theorem.)

      int dX = Math.Abs(toTest .X - centre.X);
      int dY = Math.Abs(toTest .Y - centre.Y);

      int sumOfSquares = dX * dX + dY * dY;

      int distance = (int) Math.Sqrt(sumOf Squares);

      return (radius >= distance);
      }

      Eq.


      Comment

      • illusion.admins@gmail.com

        #4
        Re: determine if a point is an an ellipse

        On Feb 20, 3:59 pm, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
        wrote:
        <illusion.adm.. .@gmail.comwrot e:
        [find point inside a circle]
        >
        This is really a maths question, not a programming question, but I have
        the C# code kicking around from a simple shape-based drawing application
        a couple of years ago. It's for circles only, not ellipses.
        >
        public bool ContainsPoint(P oint centre, int radius, Point toTest)
        {
        // Is the point inside the circle? Sum the squares of the
        x-difference and
        // y-difference from the centre, square-root it, and compare with the
        radius.
        // (This is Pythagoras' theorem.)
        >
        int dX = Math.Abs(toTest .X - centre.X);
        int dY = Math.Abs(toTest .Y - centre.Y);
        >
        int sumOfSquares = dX * dX + dY * dY;
        >
        int distance = (int) Math.Sqrt(sumOf Squares);
        >
        return (radius >= distance);
        >
        }
        >
        Eq.
        Thanks!!

        Comment

        Working...