Daa
Daa
22BCE0754
Jaya vardhan
Graham Scan
Code:
Output:
Code:
import random
# User input
arr = list(map(int, input("Enter the elements of the array (separated by spaces): ").split()))
Output:
Jarvis March
Code:
import matplotlib.pyplot as plt
# Function to find the point with the lowest x-coordinate (ties broken by y-coordinate)
def leftmost_point(points):
return min(points, key=lambda p: (p[0], p[1]))
while True:
next_point = points[0] # Pick an arbitrary point initially
for point in points:
if point == current:
continue
# Update next_point if it is more counterclockwise
if next_point == current or orientation(current, next_point, point) < 0:
next_point = point
current = next_point
if current == start: # If we’ve wrapped back to the starting point
break
hull.append(current)
return hull
# User input
print("Enter points as x, y pairs (e.g., 1,2). Enter 'done' to finish:")
points = []
while True:
inp = input("Point: ")
if inp.lower() == 'done':
break
try:
x, y = map(float, inp.split(','))
points.append((x, y))
except ValueError:
print("Invalid input. Please enter as x,y.")
Output: