Algorithm/기하
CCW 알고리즘
Ezcho
2022. 8. 11. 00:40
CCW 알고리즘
ccw는 평면에 놓여진 세 점의 방향관계를 구하는 알고리즘이다.
세 점을 주어진 순서대로 벡터화 한후 그 두 백터를 외적하면 방향이 정의된다.
-코드 [Java]
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int x3 = sc.nextInt();
int y3 = sc.nextInt();
int a = x1 * y2 + x2 * y3 + x3 * y1;
int b = y1 * x2 + y2 * x3 + y3 * x1;
if(a-b==0)
System.out.println(0);
else if(a-b>0)
System.out.println(1);
else
System.out.println(-1);
}
}