def draw_arrow_field(x_, y_, z_, u_, v_, w_, s=0.25, color=(0, 0, 1), width=1.5, head_angle=90): magnitudes = [ lm.length(vec) for vec in [(u_[x, y, z], v_[x, y, z], w_[x, y, z]) for x in x_ for y in y_ for z in z_] ] #magnitudes = [val for val in magnitudes if not val == 0] print min(magnitudes), max(magnitudes) vel_max = max(magnitudes) for u_dex, x in enumerate(x_): for v_dex, y in enumerate(y_): for w_dex, z in enumerate(z_): u = u_[u_dex, v_dex, w_dex] v = v_[u_dex, v_dex, w_dex] w = w_[u_dex, v_dex, w_dex] glPushMatrix() glTranslatef(x, y, z) conv = lm.length((u, v, w)) if conv: #pdb.set_trace() mag_scale = 2.0 * conv / vel_max #print mag_scale, 1, 1, conv, vel_max conv = 1.0 / conv dir_ = (u * conv, v * conv, w * conv) x_hat = (1, 0, 0) q_hat = np.cross(x_hat, dir_) if lm.length(q_hat): q_hat = q_hat / lm.length(q_hat) ang = lm.angle(x_hat, dir_, unit='degree') glScalef(mag_scale, 1, 1) glRotatef(ang, *q_hat) glScalef(s, s, s) draw_line(start=(0, 0, 0), end=x_hat, color=color, width=width) glTranslatef(*x_hat) glRotatef(head_angle, *x_hat) draw_triangle(color=color) else: draw_dot(color=(1, 0, 0)) glPopMatrix()
def compute_drag_f(self, medium): bvel = np.array(self.body.getLinearVel()) mvel = medium.average_velocity_over_granule(self) if not lm.length(mvel): return np.array([0, 0, 0]) rvel = mvel - bvel if not lm.length(rvel): return np.array([0, 0, 0]) rho_ = medium.rho c_drag = 1.0 area = self.compute_cross_section(mvel/lm.length(mvel)) f_x, f_y, f_z =\ 0.5*lm.dot_product(rvel, rvel)*rho_*\ area*c_drag*rvel/lm.length(rvel) return [f_x, f_y, f_z]
def draw_arrow_field(x_, y_, z_, u_, v_, w_, s = 0.25, color = (0,0,1), width = 1.5, head_angle = 90): magnitudes = [lm.length(vec) for vec in [(u_[x,y,z],v_[x,y,z],w_[x,y,z]) for x in x_ for y in y_ for z in z_]] #magnitudes = [val for val in magnitudes if not val == 0] print min(magnitudes), max(magnitudes) vel_max = max(magnitudes) for u_dex, x in enumerate(x_): for v_dex, y in enumerate(y_): for w_dex, z in enumerate(z_): u = u_[u_dex, v_dex, w_dex] v = v_[u_dex, v_dex, w_dex] w = w_[u_dex, v_dex, w_dex] glPushMatrix() glTranslatef(x, y, z) conv = lm.length((u, v, w)) if conv: #pdb.set_trace() mag_scale = 2.0*conv/vel_max #print mag_scale, 1, 1, conv, vel_max conv = 1.0/conv dir_ = (u*conv, v*conv, w*conv) x_hat = (1, 0, 0) q_hat = np.cross(x_hat, dir_) if lm.length(q_hat): q_hat = q_hat/lm.length(q_hat) ang = lm.angle(x_hat, dir_, unit = 'degree') glScalef(mag_scale, 1, 1) glRotatef(ang, *q_hat) glScalef(s, s, s) draw_line(start = (0, 0, 0), end = x_hat, color = color, width = width) glTranslatef(*x_hat) glRotatef(head_angle, *x_hat) draw_triangle(color = color) else: draw_dot(color = (1, 0, 0)) glPopMatrix()