2个回答
展开全部
public class Coordinate {
public static void main(String[] args) {
double x = 0.5;//测试点横坐标
double y = 0.3;//测试点纵坐标
final double r = 1;//半径为1
boolean isInCircle = isPointInCircle(x, y, r);
System.out.println("点(" + x + "," + y + ")" + (isInCircle? "在": "不在") + "以原点(0,0)为圆心半径为" + r + "的圆内!");
}
private static boolean isPointInCircle(double x, double y, double r) {
//园内的点必须满足x < 1 && y <1并且x*x + y*y < 1
if(Math.abs(x) >= r || Math.abs(y) >= r){
return false;
}
return Math.pow(x, 2) + Math.pow(y, 2) < 1;
}
}
------------------
点(0.5,0.3)在以原点(0,0)为圆心半径为1.0的圆内!
public static void main(String[] args) {
double x = 0.5;//测试点横坐标
double y = 0.3;//测试点纵坐标
final double r = 1;//半径为1
boolean isInCircle = isPointInCircle(x, y, r);
System.out.println("点(" + x + "," + y + ")" + (isInCircle? "在": "不在") + "以原点(0,0)为圆心半径为" + r + "的圆内!");
}
private static boolean isPointInCircle(double x, double y, double r) {
//园内的点必须满足x < 1 && y <1并且x*x + y*y < 1
if(Math.abs(x) >= r || Math.abs(y) >= r){
return false;
}
return Math.pow(x, 2) + Math.pow(y, 2) < 1;
}
}
------------------
点(0.5,0.3)在以原点(0,0)为圆心半径为1.0的圆内!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询