%matplotlib inline
from matplotlib.pyplot import *
from numpy import exp, pi
from scipy.optimize import root
def transform(theta, z00, z10, z20, z30, z40, z, z0=None):
""" Express points z, expressed in the beam-fixed reference frame, in
in the boat-fixed reference frame. Optionally the user can supply
a z0 in order to save time. In this case the user is responsible to
make sure the transformation is correct."""
def equations(p):
z0, z3, z4r, z4i = p
z4 = z4r+1j*z4i
eqs = (abs(z10-z3)-abs(z30-z10),
abs(z4-z20)-abs(z40-z20),
z0+(z30-z00)*exp(1j*theta)-z3,
z0+(z40-z00)*exp(1j*theta)-z4)
return eqs
def find_z0():
sol = root(equations, (z00, z30, z40.real, z40.imag), method='krylov')
if (sol.x[0]).imag <= z30.imag:
sol = root(equations, (z00+300j, z30, z40.real, z40.imag), method='krylov')
return sol.x[0]
if z0 is None:
z0 = find_z0()
return z0 + z*exp(1j*theta)
def plot_frame_raw(z0,z1,z2,z3,z4,z5):
plot([z0.real,z5.real], [z0.imag,z5.imag], 'k')
plot([z3.real,z4.real], [z3.imag,z4.imag], 'k')
plot([z1.real,z3.real], [z1.imag,z3.imag], 'g')
plot([z2.real,z4.real], [z2.imag,z4.imag], 'r')
axis('scaled')
def float_raw(z00, z10, z20, z30, z40, z50):
w = 700
h = 900
xn = np.linspace(-1.0,1.0,100)
yn = xn**2-1.
xf = 0.5*w*xn + ((z50-z00).real+0.5*w)
yf = h*yn + (z50-z00).imag
return xf, yf
def plot_frame(theta, z00, z10, z20, z30, z40, z50, verts=False):
z0 = transform(theta, z00, z10, z20, z30, z40, 0.)
z3 = transform(theta, z00, z10, z20, z30, z40, z30-z00, z0)
z4 = transform(theta, z00, z10, z20, z30, z40, z40-z00, z0)
z5 = transform(theta, z00, z10, z20, z30, z40, z50-z00, z0)
plot_frame_raw(z0,z10,z20,z3,z4,z5)
if verts:
plot([z20.real], [z20.imag], 'wo')
plot([z4.real], [z4.imag], 'wo')
plot([z10.real], [z10.imag], 'wo')
plot([z3.real], [z3.imag], 'wo')
def plot_float(theta, z00, z10, z20, z30, z40, z50):
xf, yf = float_raw(z00, z10, z20, z30, z40, z50)
zft = transform(theta, z00, z10, z20, z30, z40, xf + 1j*yf)
plot(zft.real, zft.imag, 'k')
axis('scaled')