21. 移动的圆 (java实现)
采用了递归的方式进行运算
题目将给出两个圆A和B的圆心坐标(x,y)和半径r,现给你一个点P,使圆A圆心沿直线运动至点P。
请问圆A在运动过程中是否会与圆B相交?(运动过程包括起点和终点)
若会相交返回1,否则返回-1。
样例
样例 1
输入:[0,0,2.5,3,2,0.5,0,2]
输出:1
主要思想:
判断两个圆是否相交 r1-r2 <= dis <= r1+r2
代码
public class Solution {
/**
* @param position: the position of circle A,B and point P.
* @return: if two circle intersect return 1, otherwise -1.
*/
int a = -1;
public int IfIntersect(double[] position) {
double Ax,Ay,Ar,Bx,By,Br,Px,Py;
Ax = position[0];
Ay = position[1];
Ar = position[2];
Bx = position[3];
By = position[4];
Br = position[5];
Px = position[6];
Py = position[7];
if (Math<