943,806 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2899
  • C# RSS
Sep 21st, 2009
0

Need a function which returns points X,Y in a Circle

Expand Post »
Hello,

I need to create a function which takes parameters for a circle and checks if a given point(x,y) lies within the circle (or on the edge).

Like this:
C# Syntax (Toggle Plain Text)
  1. public static bool PointExistsInCircle(Double CircleX,Double CircleY,Double CircleRadius,Double PointX,Double PointY)
  2. {
  3. needs to return 'true' if the point is in the circle, if not return 'false'.
  4. }

Could someone help me with this?, unfortunately i'm not good at math..

Mervin.
Last edited by MervinKoops; Sep 21st, 2009 at 5:50 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MervinKoops is offline Offline
9 posts
since Jun 2009
Sep 21st, 2009
0

Re: Need a function which returns points X,Y in a Circle

I'm not good at math either...LOL. Check out this thread, and see if you can come up with the formula you need. Then, if you need help with coding it, come on back here--OK?

Calculate Radius from X Y coord
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Sep 21st, 2009
1

Re: Need a function which returns points X,Y in a Circle

Well, the equation of a circle with radius R on the origin is x^2+y^2=R^2
All you have to do is test if this inequality is true or false : x^2+y^2 <=  R^2
If it is true the point (x,y) is in the circle, if it is equal it is on the circle, else it lies outside the circle.
It should be rather easy to write that in C#.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Sep 21st, 2009
0

Re: Need a function which returns points X,Y in a Circle

Ah okay thanks for the help .

and what would be a formula which also takes an X and Y for the circle origin?
Last edited by MervinKoops; Sep 21st, 2009 at 6:11 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MervinKoops is offline Offline
9 posts
since Jun 2009
Sep 21st, 2009
0

Re: Need a function which returns points X,Y in a Circle

Don't know exactly what you mean here but I guess it is something like this (x-a)^2+(y-b)^2 = R^2
Where a and b are the new coordinates of the center. If a and b are both zero then the circle has its center at the origin.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Sep 21st, 2009
0

Re: Need a function which returns points X,Y in a Circle

I don't understand the Circle X,Y, and Radius. Don't you just need a single center point and the radius, then draw the circle from there?
Last edited by sknake; Sep 21st, 2009 at 6:55 pm.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Sep 22nd, 2009
0

Re: Need a function which returns points X,Y in a Circle

Take a look at online book at google - Physics for game programmers By Grant Palmer

Quote ...
SUMMARY:

Determine if the point is inside the circle by computing the distance from the point to the center of the circle. If the distance is less than 1, the point is inside.
C# Syntax (Toggle Plain Text)
  1. double distance = Math.Sqrt((x-0.5)*(x-0.5) + (y-0.5)*(y-0.5));
  2. if(distance<=0.5){
  3. ...
  4. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 22nd, 2009
0

Re: Need a function which returns points X,Y in a Circle

Thanks for the help everyone. I solved it
Last edited by MervinKoops; Sep 22nd, 2009 at 12:39 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MervinKoops is offline Offline
9 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Retrieving records in batches of 50
Next Thread in C# Forum Timeline: Can you install apps made in VS 2008 on these OSs





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC