import numpy as np def get_3d_config(A,x0,nt,z_index): A, x0, nt, z_index = np.array(A), np.array(x0), np.array(nt), np.array(z_index) n_joints = (A.sum(-1)>0).sum() A = A[:n_joints,:][:,:n_joints] x0 = x0[:n_joints] nt = nt[:n_joints] n_links = int(A.sum()/2) l1,l2 = np.where(np.triu(A)) linkages = [] max_len = 0 min_len = float(np.inf) for j in range(n_links): length= np.linalg.norm(x0[l1[j]]-x0[l2[j]]) if length>max_len: max_len = float(length) if length 1: highligh_curve = [] for i in highlights: highligh_curve.append(np.pad(sol[i,:,:]*s,[[0,0],[0,1]],constant_values=z[i]+0.025)) highligh_curve = np.array(highligh_curve) else: highligh_curve = np.pad(sol[highlights[0],:,:]*s,[[0,0],[0,1]],constant_values=z[-1]+0.025) return configs, highligh_curve.tolist() def create_3d_html(A,x0,nt,z_index,sol, template_path='./static/animation.htm', save_path='./static/animated.html', highlights = [-1]): res,hc = get_animated_3d_config(A,x0,nt,z_index,sol,highlights=highlights) js_var = 'window.res = ' + str(res) + ';\n' js_var += 'window.hc = ' + str(hc) + ';' js_var += 'window.multi_high = ' + str(int(len(highlights)>1)) + ';' with open(template_path, 'r') as file: filedata = file.read() filedata = filedata.replace('{res}',js_var) with open(save_path, 'w') as file: file.write(filedata)