반응형
두 직선의 교점 구하기

분모 (x1−x2)(y3−y4)−(y1−y2)(x3−x4)=0이면 기울기가 같은것이기 때문에 두 직선은 평행 또는 일치함
This file contains 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
static void intersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { | |
int px= (x1*y2 - y1*x2)*(x3-x4) - (x1-x2)*(x3*y4 - y3*x4); | |
int py= (x1*y2 - y1*x2)*(y3-y4) - (y1-y2)*(x3*y4 - y3*x4); | |
int p = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4); | |
if(p == 0) { | |
System.out.println("parallel"); | |
return; | |
} | |
int x = px/p; | |
int y = py/p; | |
System.out.println(x + ", " + y); | |
} |
반응형
'개발' 카테고리의 다른 글
[기하] 회전하는 캘리퍼스 (Rotating calipers) (0) | 2019.07.20 |
---|---|
[기하] 컨벡스헐 (0) | 2019.07.20 |
유니티 git 설정 (0) | 2017.10.29 |
유니티 다른 오브젝트(스크립트)의 함수 호출 방법 (0) | 2017.06.18 |
MagicaVoxel 모델을 불러와서 애니메이션 추가하는 방법 (0) | 2017.05.09 |