From bdbdfa624d93a3bfd49e187e07551e66faeb6c54 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Tue, 16 Oct 2018 14:51:51 +0200 Subject: [PATCH] Added more point generation stuff --- h2/util.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/h2/util.py b/h2/util.py index 3fff2e8..ac82dc0 100644 --- a/h2/util.py +++ b/h2/util.py @@ -2,6 +2,7 @@ import random from collections import namedtuple from enum import Enum, auto from typing import Set +from math import cos, sin, sqrt, pi import matplotlib.pyplot as plt import numpy as np @@ -32,6 +33,33 @@ def display(points: Set[Point], hull: Set[Point]): plt.show() +def gen_circular_point(lower : int = 0, upper: int = 10, radius: int = 5) -> Point: + + a = random.uniform(lower, upper) * 2 * pi + + r = radius * sqrt(random.uniform(lower, upper)) + + + x = r * cos(a) + y = r * sin(a) + + return Point(x,y) + +def gen_weird_point(lower : int = 0, upper: int = 10) -> Point: + x = random.uniform(lower, upper) + y = x**2 + + return Point(x,y) + + +def gen_triangular_point(left : Point, right : Point, top : Point): + r1 = random.uniform(0,1) + r2 = random.uniform(0,1) + + return Point((1 - sqrt(r1)) * left.x + (sqrt(r1) * (1 - r2)) * right.x + (sqrt(r1) * r2) * top.x, + (1 - sqrt(r1)) * left.y + (sqrt(r1) * (1 - r2)) * right.y + (sqrt(r1) * r2) * top.y) + + def display_line_only(points: Set[Point], slope: float, intercept: float, line_points: Set[Point]): x = [point.x for point in points] y = [point.y for point in points]