void v_coef(SBasis2d f, unsigned deg, SBasis &a, SBasis &b) { a = SBasis(f.us, Linear()); b = SBasis(f.us, Linear()); for (unsigned u=0; u<f.us; u++){ a[u] = Linear(f.index(deg,u)[0], f.index(deg,u)[1]); b[u] = Linear(f.index(deg,u)[2], f.index(deg,u)[3]); } }
//see a sb2d as an sb of u with coef in sbasis of v. void u_coef(SBasis2d f, unsigned deg, SBasis &a, SBasis &b) { a = SBasis(f.vs, Linear()); b = SBasis(f.vs, Linear()); for (unsigned v=0; v<f.vs; v++){ a[v] = Linear(f.index(deg,v)[0], f.index(deg,v)[2]); b[v] = Linear(f.index(deg,v)[1], f.index(deg,v)[3]); } }
void v_coef(SBasis2d f, unsigned deg, SBasis &a, SBasis &b) { a = SBasis(); b = SBasis(); for (unsigned u=0; u<f.us; u++){ a.push_back(Linear(f.index(deg,u)[0], f.index(deg,u)[1])); b.push_back(Linear(f.index(deg,u)[2], f.index(deg,u)[3])); } }
//see a sb2d as an sb of u with coef in sbasis of v. void u_coef(SBasis2d f, unsigned deg, SBasis &a, SBasis &b) { a = SBasis(); b = SBasis(); for (unsigned v=0; v<f.vs; v++){ a.push_back(Linear(f.index(deg,v)[0], f.index(deg,v)[2])); b.push_back(Linear(f.index(deg,v)[1], f.index(deg,v)[3])); } }
SBasis2d partial_derivative(SBasis2d const &f, int dim) { SBasis2d result; for(unsigned i = 0; i < f.size(); i++) { result.push_back(Linear2d(0,0,0,0)); } result.us = f.us; result.vs = f.vs; for(unsigned i = 0; i < f.us; i++) { for(unsigned j = 0; j < f.vs; j++) { Linear2d lin = f.index(i,j); Linear2d dlin(lin[1+dim]-lin[0], lin[1+2*dim]-lin[dim], lin[3-dim]-lin[2*(1-dim)], lin[3]-lin[2-dim]); result[i+j*result.us] += dlin; unsigned di = dim?j:i; if (di>=1){ float motpi = dim?-1:1; Linear2d ds_lin_low( lin[0], -motpi*lin[1], motpi*lin[2], -lin[3] ); result[(i+dim-1)+(j-dim)*result.us] += di*ds_lin_low; Linear2d ds_lin_hi( lin[1+dim]-lin[0], lin[1+2*dim]-lin[dim], lin[3]-lin[2-dim], lin[3-dim]-lin[2-dim] ); result[i+j*result.us] += di*ds_lin_hi; } } } return result; }
SBasis extract_u(SBasis2d const &a, double u) { SBasis sb(a.vs, Linear()); double s = u*(1-u); for(unsigned vi = 0; vi < a.vs; vi++) { double sk = 1; Linear bo(0,0); for(unsigned ui = 0; ui < a.us; ui++) { bo += (extract_u(a.index(ui, vi), u))*sk; sk *= s; } sb[vi] = bo; } return sb; }
SBasis extract_v(SBasis2d const &a, double v) { SBasis sb(a.us, Linear()); double s = v*(1-v); for(unsigned ui = 0; ui < a.us; ui++) { double sk = 1; Linear bo(0,0); for(unsigned vi = 0; vi < a.vs; vi++) { bo += (extract_v(a.index(ui, vi), v))*sk; sk *= s; } sb[ui] = bo; } return sb; }