In C#, How can I find the distance between the point and center of a circle? -
i'm come solution towards finding distance point , center of circle.
i have add following method circle class, given point's x , y coordinates, in method returns whether or not point within bounds of circle or not.
i think accomplish draw of circle center point , radius, have draw 2 others points, 1 inside circle , 1 outside. how determine point inside circle , point outside of circle?
i'm asking distance between 2 points , center of circle.
here's code i've written far.
public bool contains(float px, float py) { (math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)) < (d * d); return mcontains; }
well, if have property x
, y
, radius
, you're given point (x1, y1)
, can test if it's inside circle:
bool isincircle(int x1, int y1) { return math.sqrt(math.pow(x1 - this.x, 2) + math.pow(y1 - this.y, 2)) <= this.radius; }
then check both of points - 1 give true
, other false
if want have function gets 2 points, can return int - 1 if first inside, 2 if second, 0 if none, 3 if both:
int areincircle(int x1, int y1, int x2, int y2) { bool = math.sqrt(math.pow(x1 - this.x, 2) + math.pow(y1 - this.y, 2)) <= this.radius; bool b = math.sqrt(math.pow(x2 - this.x, 2) + math.pow(y2 - this.y, 2)) <= this.radius; return && b ? 3 : (!a && !b ? 0 : (a ? 1 : 2)); }
Comments
Post a Comment