Skip to content

Instantly share code, notes, and snippets.

@opklnm102
Last active August 29, 2015 14:06
Show Gist options
  • Save opklnm102/17938b5496a6953ea639 to your computer and use it in GitHub Desktop.
Save opklnm102/17938b5496a6953ea639 to your computer and use it in GitHub Desktop.
software global project
//두개의 원을 입력받아 겹치는지,접하는지,떨어져있는지 판별
#include<stdio.h>
#include<math.h>
typedef struct circle{
double x,y,r;
}circle;
int circleRel(circle, circle);
void main(int argc, char *argv[])
{
circle cir1,cir2;
int res;
if(argc == 1){
printf("Type the coordinates(x,y) and radius(r) of first circle : ");
scanf("%lf %lf %lf",&cir1.x,&cir1.y,&cir1.r);
printf("%.2f %.2f %.2f\n",cir1.x,cir1.y,cir1.r);
printf("Type the coordinates(x,y) and radius(r) of second circle : ");
scanf("%lf %lf %lf",&cir2.x,&cir2.y,&cir2.r);
printf("%.2f %.2f %.2f\n",cir2.x,cir2.y,cir2.r);
}
else if(argc == 7){
printf("%s %s %s %s %s %s\n",argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]);
cir1.x = atof(argv[1]);
cir1.y = atof(argv[2]);
cir1.r = atof(argv[3]);
cir2.x = atof(argv[4]);
cir2.y = atof(argv[5]);
cir2.r = atof(argv[6]);
}
else{
printf("Error!\n");
printf("\t(Usage> file\n");
printf("\t<Usage> file x1 y1 r1 x2 y2 r2\n");
return;
}
if(cir1.r < 0 || cir2.r <0){
printf("input radius erroe!!\n");
return;
}
res=circleRel(cir1,cir2);
switch(res){
case 0 : printf("Two circle are overlapped\n"); break;
case 1 : printf("Two circles are met\n"); break;
case 2 : printf("Two circles are distant\n"); break;
}
}
int circleRel(circle c1, circle c2){
double distance;
double r1,r2; //r1>r2
distance=sqrt((pow(c2.x-c1.x,2)+pow(c2.y-c1.y,2)));
if(c1.r>c2.r){
r1=c1.r;
r2=c2.r;
}
else{
r1=c2.r;
r2=c1.r;
}
if(distance == r1-r2 || distance == r1+r2) // 내접 or 외접
return 1;
else if(distance > r1+r2 || distance < r1-r2) //외부 or 내부
return 2;
else if(r1-r2 < distance && distance < r1+r2) //두점이 만날때
return 0;
}
@princox
Copy link

princox commented Sep 24, 2014

코드 잘 짰네요 붐업

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment