티스토리 뷰

IT/JAVA

[java] 두 원의 접점 갯수 찾기

긍정탁 2021. 11. 25. 16:26
import java.io.IOException;
import java.util.*;

public class Main {
   public static void main(String[] args) throws IOException {

      Scanner sc = new Scanner(System.in);
      
          int cnt = sc.nextInt();

          double x1,y1,r1;
          double x2,y2,r2;
          double dist=0;
          double r=0;
          double dr=0;
          int ret=0;

          for(int i =0 ; i<cnt; i++){

           ret=-99;
       
           x1=sc.nextInt();
           y1=sc.nextInt();
           r1=sc.nextInt();
           x2=sc.nextInt();
           y2=sc.nextInt();
           r2=sc.nextInt();
      
           dist=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
           
           r= r1+r2;
           dr= Math.abs(r1-r2);

           if(dist==0){      
             if(r1==r2){       //1
              ret=-1;
                 }
                 else{
                ret=0;
             }
           }
           else if(dist>r){
       ret=0;
           }
           else if(dist==r){      //4 
       ret=1;
           }
           else if(dist==dr){  //3
         ret=1;
           }
           else if(dist<dr){   //2
             ret=0;
           }
           else { 
             ret =2 ;
                 }


           if(ret==-99){
               System.out.println("no data found");

           }
           else{

           System.out.println(ret);
           }



          }

          
      
   } // end of Main
                 
} // end of class Main
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31