Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def boundaryFunction(parameter):
- return 1 + 0.1 * np.cos(parameter)
- def boundaryDerivative(parameter):
- return -0.1 * np.sin(parameter)
- def trajectoryFunction(parameter):
- aux = np.sin(beta - phi) / np.sin(beta - parameter)
- return boundaryFunction(phi) * aux
- def difference(parameter):
- return trajectoryFunction(parameter) - boundaryFunction(parameter)
- def integrand(parameter):
- rr = boundaryFunction(parameter)
- dd = boundaryDerivative (parameter)
- return np.sqrt(rr ** 2 + dd ** 2)
- ##### Main #####
- length_vals = np.array([], dtype=np.float64)
- alpha_vals = np.array([], dtype=np.float64)
- # nof initial phi angles, alpha angles, and nof collisions for each.
- n_phi, n_alpha, n_cols, count = 10, 10, 10, 0
- # Length of the boundary
- total_length, err = integrate.quad(integrand, 0, 2 * np.pi)
- for phi in np.linspace(0, 2 * np.pi, n_phi):
- for alpha in np.linspace(0, 2 * np.pi, n_alpha):
- for n in np.arange(1, n_cols):
- nu = np.arctan(boundaryFunction(phi) / boundaryDerivative(phi))
- beta = np.pi + phi + alpha - nu
- # Determines next impact coordinate.
- bnds = (0, 2 * np.pi)
- phi_new = optimize.minimize_scalar(difference, bounds=bnds, method='bounded').x
- nu_new = np.arctan(boundaryFunction(phi_new) / boundaryDerivative(phi_new))
- # Reflection angle with relation to tangent.
- alpha_new = phi_new - phi + nu - nu_new - alpha
- # Arc length for current phi value.
- arc_length, err = integrate.quad(integrand, 0, phi_new)
- # Append values to list
- length_vals = np.append(length_vals, arc_length / total_length)
- alpha_vals = np.append(alpha_vals, alpha)
- count += 1
- print "{}%" .format(100 * count / (n_phi * n_alpha))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement