设计一个点类(Point)和一个圆类(Circle),输入点坐标和圆心坐标及半径,判断点和圆的关系(点在圆内,点在圆上,点在圆外)
时间: 2024-10-27 16:11:32 浏览: 18
设计一个点类(Point)和一个圆类(Circle)可以使用Python来实现,这里是一个简单的示例:
```python
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class Circle:
def __init__(self, center_x, center_y, radius):
self.center = Point(center_x, center_y)
self.radius = radius
def is_point_in_circle(self, point):
distance = ((point.x - self.center.x)**2 + (point.y - self.center.y)**2)**0.5
return distance < self.radius # 点在圆内
return distance == self.radius # 点在圆上
return distance > self.radius # 点在圆外
# 示例使用
circle = Circle(0, 0, 5)
point = Point(3, 4)
if circle.is_point_in_circle(point):
print("点在圆内")
elif circle.is_point_on_circle(point):
print("点在圆上")
else:
print("点在圆外")
阅读全文