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

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 9
Reputation: MervinKoops is an unknown quantity at this point 
Solved Threads: 0
MervinKoops MervinKoops is offline Offline
Newbie Poster

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

 
0
  #1
Sep 21st, 2009
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 920
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 147
DdoubleD DdoubleD is offline Offline
Posting Shark

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

 
0
  #2
Sep 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,958
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 283
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

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

 
1
  #3
Sep 21st, 2009
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#.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: MervinKoops is an unknown quantity at this point 
Solved Threads: 0
MervinKoops MervinKoops is offline Offline
Newbie Poster

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

 
0
  #4
Sep 21st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,958
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 283
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

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

 
0
  #5
Sep 21st, 2009
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,231
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 576
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

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

 
0
  #6
Sep 21st, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,636
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

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

 
0
  #7
Sep 22nd, 2009
Take a look at online book at google - Physics for game programmers By Grant Palmer

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.
  1. double distance = Math.Sqrt((x-0.5)*(x-0.5) + (y-0.5)*(y-0.5));
  2. if(distance<=0.5){
  3. ...
  4. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: MervinKoops is an unknown quantity at this point 
Solved Threads: 0
MervinKoops MervinKoops is offline Offline
Newbie Poster

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

 
0
  #8
Sep 22nd, 2009
Thanks for the help everyone. I solved it
Last edited by MervinKoops; Sep 22nd, 2009 at 12:39 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
math

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC