2018-10-09 17:26:55 +00:00
|
|
|
import random
|
|
|
|
from collections import namedtuple
|
|
|
|
from enum import Enum, auto
|
|
|
|
from typing import Set
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
Point = namedtuple('Point', 'x y')
|
|
|
|
Vector = namedtuple('Vector', 'x y')
|
|
|
|
|
|
|
|
|
|
|
|
def gen_point(lower: int = 0, upper: int = 10) -> Point:
|
|
|
|
a = random.uniform(lower, upper)
|
|
|
|
b = random.uniform(lower, upper)
|
|
|
|
|
2018-10-11 12:38:59 +00:00
|
|
|
#x_i = random.uniform(lower, upper)
|
|
|
|
#p_i = Point(x_i, a * x_i + b)
|
|
|
|
return Point(a, b)
|
2018-10-09 17:26:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def display(points: Set[Point], hull: Set[Point]):
|
|
|
|
x = [point.x for point in points]
|
|
|
|
y = [point.y for point in points]
|
|
|
|
|
|
|
|
h_x = [point.x for point in hull]
|
|
|
|
h_y = [point.y for point in hull]
|
|
|
|
|
|
|
|
plt.plot(h_x, h_y, 'ro')
|
|
|
|
|
|
|
|
plt.scatter(x, y)
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
def display_line_only(points: Set[Point], slope: int, intercept: int, line_points: Set[Point]):
|
|
|
|
x = [point.x for point in points]
|
|
|
|
y = [point.y for point in points]
|
|
|
|
|
|
|
|
plt.scatter(x, y)
|
|
|
|
|
|
|
|
# Plot a line from slope and intercept
|
|
|
|
axes = plt.gca()
|
|
|
|
x_vals = np.array(axes.get_xlim())
|
|
|
|
y_vals = intercept + slope * x_vals
|
|
|
|
|
|
|
|
for point in line_points:
|
|
|
|
plt.plot(point.x, point.y, 'go')
|
|
|
|
|
|
|
|
plt.plot(x_vals, y_vals, '--')
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
class Side(Enum):
|
|
|
|
ON = auto()
|
|
|
|
ABOVE = auto()
|
|
|
|
BELOW = auto()
|