2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

added plot for cubic functions; some restructuring

This commit is contained in:
Martin Thoma 2013-11-23 01:18:22 +01:00
parent 22f18e4f15
commit d06eb991ef
2 changed files with 111 additions and 46 deletions

View file

@ -11,25 +11,22 @@ def euclideanDist(p1, p2):
from math import sqrt
return sqrt((p1.x-p2.x)**2 + (p1.y-p2.y)**2)
def getMinDist(y, precision=0.001, startX=0, endX=3):
"""Get x of point on (x,x^2) that has minimal distance to given Point."""
def getMinDist(p1, precision=0.001, startX=0, endX=3):
"""Get x of point on (x,x^2) that has minimal distance to given Point p."""
minDist = -1
p1 = Point(0, y)
for x in numpy.arange(startX, endX, precision):
p2 = Point(x, x**2)
dist = euclideanDist(p1, p2)
if minDist == -1 or dist < minDist:
minDist = dist
#print(dist)
else:
if abs(i-minDist) <0.005:
print("x: %s" % str(x))
break
return minDist
for i in numpy.arange(0, 3, 0.01):
minDist = getMinDist(i)
"""for i in numpy.arange(0, 3, 0.01):
minDist = getMinDist(Point(0, i))
if abs(i-minDist) < 0.005:
print(i, minDist)
print(i, minDist)"""
print(getMinDist(Point(0,4.25), precision=0.001, startX=0, endX=3))
#print(euclideanDist(Point(0,5),Point(2, 2**2)))
#print(getMinDist(5, 0.00001, 2, 3))