Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Created March 31, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesBuchner/3393178747b518c0ecb3 to your computer and use it in GitHub Desktop.
Save JohannesBuchner/3393178747b518c0ecb3 to your computer and use it in GitHub Desktop.
import numpy
from numpy import cos, sin, exp, log, pi, tan, arccos, arcsin, arctan
import matplotlib.pyplot as plt
# make a quadratic figure
plt.figure(figsize=(6, 6))
# generate 400 points between 0 and 1
t = numpy.linspace(0, 1, 40)
print 't = ', t
# plot the curve
# I think it is a circle?
# then go from 0 to 90 degrees
x = sin(t*pi/2)
y = cos(t*pi/2)
plt.plot(x, y, '-')
# if you want text, then place it like this
t_text = 60 / 180. * pi # at 60 degrees
x_text = sin(t_text)
y_text = cos(t_text)
plt.text(x_text, y_text, 'my text here')
# if you want arrows, then place them like this
x_start = 0
y_start = y_text
x_end = x_text
y_end = y_text
plt.arrow(x_start, y_start, x_end - x_start, y_end - y_start, length_includes_head=True)
# axes labels
plt.ylabel('y')
plt.xlabel('x')
# store to file
plt.savefig('optpath_cartoon.png')
plt.savefig('optpath_cartoon.pdf', bbox_inches='tight')
plt.close()
# now the second plot:
# for every possible W we want to compute the formula
# W is between 0 and 1 in y
W_y = y
# it is always 0 in x
W_x = numpy.zeros_like(W_y)
A_t = t
A_x = x
A_y = y
F_x = 0.5
F_y = 0
# compute distance between W and A
WA = ((W_x - A_x)**2 + (W_y - A_y)**2)**0.5
print WA
# compute distance between A and F
AF = ...
print AF
OP = WA + AF
plt.plot(W_y, OP)
plt.savefig('optpath.pdf', bbox_inches='tight')
plt.savefig('optpath.png', bbox_inches='tight')
plt.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment