๐Ÿง ์™ธ์  ๊ด€๋ จ ์•Œ๊ณ ๋ฆฌ์ฆ˜, CCW ( Counter Clock Wise )

๐Ÿค” ์„œ๋กœ ๋‹ค๋ฅธ ์„ธ์  ์‚ฌ์ด์˜ ๋„“์ด๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹, CCW๋ž€?

CCW(Counter Clock Wise)๋Š” ๋‹ค๋ฅธ ์˜๋ฏธ๋กœ ๋ฒกํ„ฐ์˜ ์™ธ์ ๊ฐ’์ด๋ผ๊ณ ๋„ ํ•œ๋‹ค.
(CCW์˜ ์ ˆ๋Œ“๊ฐ’ / 2)์€ ์„ธ ์ ์˜ ๋ฒกํ„ฐ์˜ ์™ธ์ ๊ฐ’ (์„ธ์ ์œผ๋กœ ํ•˜๋Š” ์‚ผ๊ฐํ˜• ๋„“์ด)์ด๋‹ค.
์ด๋•Œ, ์‹œ๊ณ„๋ฐฉํ–ฅ์˜ ์™ธ์ ๊ฐ’์€ ์Œ์ˆ˜์˜ ๋„“์ด์ด๊ณ 
๋ฐ˜์‹œ๊ณ„๋ฐฉํ–ฅ์˜ ์™ธ์ ๊ฐ’์€ ์–‘์ˆ˜์˜ ๋„“์ด์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 


CCW = (x1y2 + x2y3 + x3y1) - (x2y1 + x3y2 + x1y3)โ€‹

 

๋ณดํ†ต, ์›์ ์„ ์„ธ ์ ์ค‘ ํ•˜๋‚˜์— ํฌํ•จ์‹œํ‚ค๊ฒŒ๋˜๋ฉด ๋ฏธ์ง€์ˆ˜ ๊ฐœ์ˆ˜๊ฐ€ ์ค„์–ด๋“ค์–ด ๊ณ„์‚ฐ์ด ํŽธํ•ด์ง„๋‹ค.

- ์ด๋•Œ, ํ–‰๋ ฌ์‹์œผ๋กœ ๋„“์ด๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. (์šฐ๋ฆฌ๊ฐ€ ์ตํžˆ ๋“ค์–ด๋ณธ ์‹ ๋ฐœ๋ˆ ๊ณต์‹์ด๋‹ค.)

 

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 11758 (CCW, ์™ธ์ )    Gold V 




๐Ÿคซ  solution_11758

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

CCW = (x1*y2 + x2*y3 + x3*y1) - (x2*y1 + x3*y2 + x1*y3)

if CCW < 0:
    print(-1)
if CCW > 0:
    print(1)
if CCW == 0:
    print(0)

 

 

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 2166 (CCW, ์™ธ์ )    Gold V 


๐Ÿคซ  solution_2166

num = int(input())
x , y = [] , []
for i in range(num):
    X, Y = map(int,input().split())
    x.append(X)
    y.append(Y)

x.append(x[0])
y.append(y[0])

S = 0

for i in range(num):
    S += (x[i]*y[i+1] - x[i+1]*y[i])

print(round(abs(S)/2, 1))

 

 

 

 

 

 

 

 

 

๐Ÿง ๋ฐฑ์ค€ 17386, 17387 (CCW, ์™ธ์ )   Gold III, Gold II 




๐Ÿคซ  Algorithm 

https://velog.io/@jini_eun/%EB%B0%B1%EC%A4%80-17387%EB%B2%88-%EC%84%A0%EB%B6%84-%EA%B5%90%EC%B0%A8-2-Java-Python





๐Ÿคซ  solution_17387

import sys
input = sys.stdin.readline

x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())

point = []
point.append([x1, y1])
point.append([x2, y2])
point.append([x3, y3])
point.append([x4, y4])
A, B, C, D = point[0], point[1], point[2], point[3]


def ccw(p1, p2, p3):
    X1, X2, X3 = p1[0], p2[0], p3[0]
    Y1, Y2, Y3 = p1[1], p2[1], p3[1]
    CCW = (X1*Y2 + X2*Y3 + X3*Y1) - (X2*Y1 + X3*Y2 + X1*Y3)
    if CCW > 0:
        return 1
    elif CCW < 0:
        return -1
    else:
        return 0


def checkCross(a, b, c, d):
    result = 0
    p123, p124 = ccw(a, b, c), ccw(a, b, d)
    p341, p342 = ccw(c, d, a), ccw(c, d, b)

    if (p123 * p124 <= 0 and p341 * p342 <= 0) or (p123 * p124 == 0 and p341 * p342 == 0):
        if min(a[0], b[0]) <= max(c[0], d[0]) and \
                min(c[0], d[0]) <= max(a[0], b[0]) and \
                min(a[1], b[1]) <= max(c[1], d[1]) and \
                min(c[1], d[1]) <= max(a[1], b[1]):
            result = 1
    return result

print(checkCross(A, B, C, D))

 

+ Recent posts