mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
Adjust Python code to follow PEP8
This commit is contained in:
parent
b36776fc27
commit
de1ad26035
14 changed files with 349 additions and 311 deletions
|
@ -2,31 +2,36 @@
|
|||
|
||||
import numpy
|
||||
|
||||
|
||||
class Point:
|
||||
"""Represents a point in 2D."""
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def euclideanDist(p1, p2):
|
||||
|
||||
def euclidean_dist(p1, p2):
|
||||
"""Euclidean distance of two 2D points."""
|
||||
from math import sqrt
|
||||
return sqrt((p1.x-p2.x)**2 + (p1.y-p2.y)**2)
|
||||
|
||||
def getMinDist(p1, precision=0.001, startX=0, endX=3):
|
||||
|
||||
def get_min_dist(p1, precision=0.001, start_x=0, end_x=3):
|
||||
"""Get x of point on (x,x^2) that has minimal distance to given Point p."""
|
||||
minDist = -1
|
||||
for x in numpy.arange(startX, endX, precision):
|
||||
min_dist = -1
|
||||
for x in numpy.arange(start_x, end_x, precision):
|
||||
p2 = Point(x, x**2)
|
||||
dist = euclideanDist(p1, p2)
|
||||
if minDist == -1 or dist < minDist:
|
||||
minDist = dist
|
||||
return minDist
|
||||
dist = euclidean_dist(p1, p2)
|
||||
if min_dist == -1 or dist < min_dist:
|
||||
min_dist = dist
|
||||
return min_dist
|
||||
|
||||
"""for i in numpy.arange(0, 3, 0.01):
|
||||
minDist = getMinDist(Point(0, i))
|
||||
if abs(i-minDist) < 0.005:
|
||||
print(i, minDist)"""
|
||||
min_dist = get_min_dist(Point(0, i))
|
||||
if abs(i-min_dist) < 0.005:
|
||||
print(i, min_dist)"""
|
||||
|
||||
print(getMinDist(Point(0,4.25), precision=0.001, startX=0, endX=3))
|
||||
#print(euclideanDist(Point(0,5),Point(2, 2**2)))
|
||||
print(get_min_dist(Point(0, 4.25), precision=0.001, start_x=0, end_x=3))
|
||||
# print(euclidean_dist(Point(0,5),Point(2, 2**2)))
|
||||
|
||||
#print(getMinDist(5, 0.00001, 2, 3))
|
||||
# print(get_min_dist(5, 0.00001, 2, 3))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue