//圆类
public class Cirle {
Point heart;
double r;
public Cirle(double r) {
this.r = r;
}
//给个点 给个半径
public Cirle(Point heart, double r) {
this.heart = heart;
this.r = r;
}
public double area() {
return r * r * 3.14;
}
}
点类
public class Point {
int x;
int y;
public Point(){
}public Point(int x,int y){
this.x=x;
this.y=y;
}
}
测试类
public class test {
public static void main(String[] args) {
//给定点
Point p1 = new Point(0, 3);
//圆心
Point heart = new Point(3, 3);
Cirle c1 = new Cirle(heart, 3);
//点到点的距离
int i = (p1.x - heart.x) * (p1.x - heart.x) + (p1.y - heart.y) * (p1.y - heart.y);
double rr = c1.r * c1.r;
if (i > rr) {
System.out.println("点在圆外");
}
if (i < rr) {
System.out.println("点在圆内");
} else {
System.out.println("点在圆上");
}
}
}