-
-
Save opklnm102/87ee2e0b133a028c5b4c to your computer and use it in GitHub Desktop.
software global project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//x,y좌표상의 한점이 주어진 직사각형 안에 위치하는지 검사 | |
#include<stdio.h> | |
#include<stdlib.h> | |
typedef struct point{ //좌표값은 정수 | |
int x; | |
int y; | |
}point; | |
typedef struct rect{ | |
struct point pt1; | |
struct point pt2; | |
}rect; | |
int PtinRect(point, rect); | |
int main(int argc,char *argv[]) | |
{ | |
point p; | |
rect re; | |
int res; | |
if(argc == 1){ | |
printf("input dot>> "); //점의 위치를입력 받는다 | |
scanf("%d %d",&p.x,&p.y); | |
while(1) | |
{ | |
printf("input rectangle>> "); //사각형의 위치를 입력 받는다 | |
scanf("%d %d %d %d",&re.pt1.x,&re.pt1.y,&re.pt2.x,&re.pt2.y); | |
fflush(stdin); | |
if(re.pt1.x == re.pt2.x || re.pt1.y == re.pt2.y) | |
printf("직사각형이 아니라 직선임(다시입력)\n"); | |
else | |
break; | |
} | |
} | |
else if(argc == 7){ | |
printf("dot(%s, %s) rect1(%s, %s) rect2(%s, %s)\n",argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]); | |
p.x = atoi(argv[1]); | |
p.y = atoi(argv[2]); | |
re.pt1.x = atoi(argv[3]); | |
re.pt1.y = atoi(argv[4]); | |
re.pt2.x = atoi(argv[5]); | |
re.pt2.y = atoi(argv[6]); | |
} | |
else{ | |
printf("Error!\n"); | |
printf("\t(Usage> file\n"); | |
printf("\t<Usage> file dot(x,y) rect1(x,y) rect2(x,y)\n"); | |
return; | |
} | |
res=PtinRect(p,re); | |
switch(res){ | |
case 1 : printf("사각형 안에 있음\n"); break; | |
case -1 : printf("사각형 안에 없음\n"); break; | |
} | |
} | |
int PtinRect(point p, rect re){ | |
int x1,x2,y1,y2; //x2>x1, y2>y1 | |
if(re.pt1.x>re.pt2.x){ //x2>x1 | |
x2=re.pt1.x; | |
x1=re.pt2.x; | |
} | |
else{ | |
x2=re.pt2.x; | |
x1=re.pt1.x; | |
} | |
if(re.pt1.y>re.pt2.y){ //y2>y1 | |
y2=re.pt1.y; | |
y1=re.pt2.y; | |
} | |
else{ | |
y2=re.pt2.y; | |
y1=re.pt1.y; | |
} | |
//걸처도 속한것 | |
if((x1 <= p.x && p.x <= x2) && (y1 <= p.y && p.y <= y2)) | |
return 1; | |
else | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment