Ivan
Ivan

Reputation: 347

Circle Distance Question

This is my homework question:

Expand on your Circle class by adding a method called exactly dist() which takes the x and y values of a point, and returns the distance of the point in coordinate space from the outside of the circle (or zero if the point is on or inside the circle).

The following code:

myCircle = Circle(1,1,1)
print myCircle.dist(3,4)

Should print an output of approximately:

2.6055512754639891

However I cant understand the question. What does it mean to return the point in coordinate space from the outside of the circle? Can you please explain it?

Upvotes: 0

Views: 2510

Answers (4)

Jason
Jason

Reputation: 674

Find the distance between the center of the circle and the given point. Subtract the radius from the distance. Negative values are inside the circle.

Upvotes: 4

John La Rooy
John La Rooy

Reputation: 304147

>>> from math import hypot
>>> hypot(3-1,4-1)    # How far is the point from the centre of the circle?
3.6055512754639891
>>> hypot(3-1,4-1)-1  # Now subtract the radius
2.6055512754639891
>>> 

Upvotes: 0

abcd
abcd

Reputation: 42225

You can easily check if the point is inside the circle on not. Once you've done that, and determined it is outside, you need to find a line normal to the circle and passing through the point. The length of the line from the circumference of the circle gives you the answer.

Hint: Any line passing through the center of the circle is normal to it.

So you have the point (x,y), radius r and center (x0,y0). I think you have enough information here to solve the problem :)

Upvotes: 2

ennuikiller
ennuikiller

Reputation: 46965

It probably means the distance to the closest point on the circle, so its a min-max problem wherre you are minimizing the distance of the point to circumfurance

Upvotes: 0

Related Questions