From 79a0cbd60263467cb0dae08834c10081cf36d93c Mon Sep 17 00:00:00 2001 From: 202410715044 ADLANTHORIQ SYAHPUTRA S <202410715044@mhs.ubharajaya.ac.id> Date: Sun, 11 May 2025 18:07:23 +0700 Subject: [PATCH] Update Punya_adlan_Titik Dalam Segiempat.py --- Punya_adlan_Titik Dalam Segiempat.py | 109 ++++++++++++++------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/Punya_adlan_Titik Dalam Segiempat.py b/Punya_adlan_Titik Dalam Segiempat.py index d541078..da0f22c 100644 --- a/Punya_adlan_Titik Dalam Segiempat.py +++ b/Punya_adlan_Titik Dalam Segiempat.py @@ -1,54 +1,55 @@ - -import winsound - -frequency = 2500 -duration = 1000 -winsound.Beep(frequency, duration) -print('Created by adlan') -print('') - -def is_point_in_polygon(x, y, polygon): - n = len(polygon) - inside = False - px, py = x, y - - for i in range(n): - j = (i + 1) % n - xi, yi = polygon[i] - xj, yj = polygon[j] - - intersect = ((yi > py) != (yj > py)) and \ - (px < (xj - xi) * (py - yi) / ((yj - yi) + 1e-10) + xi) - if intersect: - inside = not inside - - return inside - -def process_input(data_lines): - results = [] - for line in data_lines: - - line = line.replace(",", " ") - nums = list(map(float, line.strip().split())) - - - zx, zy = nums[0], nums[1] - - - polygon = [(nums[i], nums[i+1]) for i in range(2, len(nums), 2)] - - if is_point_in_polygon(zx, zy, polygon): - results.append("YA") - else: - results.append("TIDAK") - return results - -data_input = [ - "1,1 2,2 4,2 4,4 2,4", - "0,0 0,5 8,5 8,0 0,0", - "0,0 0,5 8,5 8,0 0,0" -] - -hasil = process_input(data_input) -for i, res in enumerate(hasil, 1): - print(f"h#{i}: {res}") +print('Created by adlan') +print('Created by adlan') +import winsound + +frequency = 2500 +duration = 1000 +winsound.Beep(frequency, duration) +print('Created by adlan') +print('') + +def is_point_in_polygon(x, y, polygon): + n = len(polygon) + inside = False + px, py = x, y + + for i in range(n): + j = (i + 1) % n + xi, yi = polygon[i] + xj, yj = polygon[j] + + intersect = ((yi > py) != (yj > py)) and \ + (px < (xj - xi) * (py - yi) / ((yj - yi) + 1e-10) + xi) + if intersect: + inside = not inside + + return inside + +def process_input(data_lines): + results = [] + for line in data_lines: + + line = line.replace(",", " ") + nums = list(map(float, line.strip().split())) + + + zx, zy = nums[0], nums[1] + + + polygon = [(nums[i], nums[i+1]) for i in range(2, len(nums), 2)] + + if is_point_in_polygon(zx, zy, polygon): + results.append("YA") + else: + results.append("TIDAK") + return results + +data_input = [ + "1,1 2,2 4,2 4,4 2,4", + "0,0 0,5 8,5 8,0 0,0", + "0,0 0,5 8,5 8,0 0,0" +] + +hasil = process_input(data_input) +for i, res in enumerate(hasil, 1): + print(f"h#{i}: {res}")