473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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...this point is in the rectangle making up ellipse
but NOT the ellipse itself.

Thanks for and advice.
Feb 20 '08 #1
3 9743
On Wed, 20 Feb 2008 12:47:07 -0800, <il*************@gmail.comwrote:
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
Feb 20 '08 #2
<il*************@gmail.comwrote:
[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(Point 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(sumOfSquares);

return (radius >= distance);
}

Eq.
Feb 20 '08 #3
On Feb 20, 3:59 pm, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:
<illusion.adm...@gmail.comwrote:
[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(Point 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(sumOfSquares);

return (radius >= distance);

}

Eq.
Thanks!!
Feb 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nanda | last post by:
hi, try this, bmp=new Bitmap(Width,Height); g=Graphics.FromImage(bmp); g.DrawEllipse(Pens.Red, new Rectangle(0, 0, 100, 100)); g.Save();...
3
by: Logan McKinley | last post by:
I need to draw a dot where ever the user clicks (which will be on either the form or a couple dynamically placed picture boxes). I thought the following code should work: //--- static public...
5
by: lgeastwood | last post by:
I have tweaked the PictureBox97.mdb (Stephen Lebans <www.lebans.com>) code to nicely draw lines, rectangles and circles to the specs that I input. I'm at a loss though with trying to setup an...
11
by: Christopher Ireland | last post by:
Hello! Using the definition for en ellipse (http://en.wikipedia.org/wiki/Ellipse) I can draw an arc of points. However, the end points of this arc do not coincide with the end points of an arc...
2
by: weird0 | last post by:
I wanted to draw an ellipse using c# with System.Drawing.Graphics. I tried out several tutorials and none of them worked and there seems to be something missing. One did execute without any errors...
1
by: PankajGaur | last post by:
Hi, I need to create a Ellipse shaped user control which have folloiwng attributes: 1) The edges are smooth 2) The control shuld only be selected when click on the ellipse shape & not when...
8
by: =?Utf-8?B?RGFu?= | last post by:
I would like to draw an ellipse on a windows form and through mouse drags stretch, rotate and relocate the ellipse. Thanks in advance - Dan
0
by: John Lueders | last post by:
This code is in VB.Net. Hope it is helpful. Did you use the GraphicsPath's IsVisible function? You would need to calculate the 'RectangleF' in the 'AddEllipse' method, but that should be easy...
0
by: =?Utf-8?B?UGFua2FqR2F1cg==?= | last post by:
Hi, I need to create a Ellipse shaped user control which have folloiwng attributes: 1) The edges are smooth 2) The control shuld only be selected when click on the ellipse shape & not when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.