diff --git a/src/rotating_field.py b/src/rotating_field.py new file mode 100644 index 0000000..9ad6188 --- /dev/null +++ b/src/rotating_field.py @@ -0,0 +1,55 @@ +import numpy as np +import matplotlib.pyplot as plt + +plot_fontsize = 12 + +in_rotvector = [0, 0, 1] # [-] +in_rotcenter = [0, 0, 0] # [uT] +in_rotmag = 10 # [uT] +in_rotrate = 1 # [deg/s] +in_timestep = 1 # [s] + +# Normalize rotation vector +if np.linalg.norm(in_rotvector)==0: + # ui_print("Error: Rotation axis cannot be singular.") + raise ValueError('Zero vector for rotation axis given!') +else: + v = in_rotvector / np.linalg.norm(in_rotvector) +# Find perpendiculat vectors +if v[1] == 0 and v[2] == 0: + a = np.cross(v, [0, 1, 0]) +else: + a = np.cross(v, [1, 0, 0]) +b = np.cross(v, a) + +print(v) +print(a) +print(b) +# Some vectors +c = [1, 2, 3] +r = in_rotmag + +# Get full rotation array +cycle_time = (360/in_rotrate)/in_timestep + +arr_len = int(np.floor(cycle_time/in_timestep)) +th = 0 # [rad] +x = np.zeros(arr_len) +y = np.zeros(arr_len) +z = np.zeros(arr_len) +# Calculate vectors +for i in range(arr_len): + th = th+in_rotrate*np.pi/180 + x[i] = in_rotcenter[0] + in_rotmag*np.cos(th)*a[0]+r*np.sin(th)*b[0] + y[i] = in_rotcenter[1] + in_rotmag*np.cos(th)*a[1]+r*np.sin(th)*b[1] + z[i] = in_rotcenter[2] + in_rotmag*np.cos(th)*a[2]+r*np.sin(th)*b[2] + +ax = plt.figure().add_subplot(projection='3d') +ax.plot(x[0], y[0], z[0], 'o', color='blue') +ax.plot(x, y, z, label='curve in (x, y,z)') +ax.plot(x[arr_len-1], y[arr_len-1], z[arr_len-1], '^', color='red') +ax.set_xlabel(r'$B_x [{\mu}T]$', fontsize=plot_fontsize) +ax.set_ylabel(r'$B_y [{\mu}T]$', fontsize=plot_fontsize) +ax.set_zlabel(r'$B_z [{\mu}T]$', fontsize=plot_fontsize) +plt.show() +