void PatchSample::sample_frustum(double hfov, double vfov, int nh, int nv, Vector3d p, Vector3d u, MatrixXd &mx, MatrixXd &my, MatrixXd &mz) { //TBD: check input args // pointing, up, left p = p/p.norm(); u = u/u.norm(); Vector3d l = u.cross(p); // sample like a camera would double ll = (tan(hfov/2.0)*((double)(nh-1)))/nh; double uu = (tan(vfov/2.0)*((double)(nv-1)))/nv; RowVectorXd y; y.setLinSpaced(nh,-ll,ll); MatrixXd yy; yy = y.replicate(nv,1); VectorXd z; z.setLinSpaced(nv,-uu,uu); MatrixXd zz; zz = z.replicate(1,nh); MatrixXd xx = MatrixXd::Ones(nv,nh); MatrixXd nn = (xx.array().square() + yy.array().square() + zz.array().square()).cwiseSqrt(); xx = xx.array() / nn.array(); yy = yy.array() / nn.array(); zz = zz.array() / nn.array(); // rotation matrix Matrix3d rr; rr << p, l, u; // rotate points MatrixXd xyz; MatrixXd cam (3,xx.rows()*xx.cols()); cam.row(0) = vectorizeColWise(xx); cam.row(1) = vectorizeColWise(yy); cam.row(2) = vectorizeColWise(zz); xyz = rr*cam; // extract coordinates xx = xyz.row(0); yy = xyz.row(1); zz = xyz.row(2); mx = Map<MatrixXd>(xx.data(),nv,nh); my = Map<MatrixXd>(yy.data(),nv,nh); mz = Map<MatrixXd>(zz.data(),nv,nh); }
int main() { VectorXd v; v.setLinSpaced(5,0,1); // std::cout<<JacobiP(v,0,0,4); // std::cout<<Vandermonde1D(4,v); // std::cout<<JacobiGQ(0,0,4); int K=4; int N=3; int Nv=K+1; startUp1d ob(N,K); }
MatrixXd NumInt::GuassQaudrature(const int& N, double& a, double& b) { int N0=N-1; const int N1 = N0+1; const int N2 = N0+2; VectorXd xu; xu.setLinSpaced(N1,-1.0,1.0); // Legendre-Gauss-Vandermonde Matrix //Matrix<double,N1,N2> L = Matrix<double,N1,N2>::Zero(); MatrixXd L(N1,N2); L = MatrixXd::Zero(N1,N2); // Derivative of Legendre-Gauss-Vandermonde Matrix //Matrix<double,N1,1> Lp = Matrix<double,N1,1>::Zero(); VectorXd Lp(N1); Lp = VectorXd::Zero(N1); VectorXd dum; dum.setLinSpaced(N1,0.0,N0); ArrayXd y; y = cos((2*dum.array()+1)*M_PI/(2*N0+2))+(0.27/N1)*sin(M_PI*xu.array()*N0/N2); double deps = std::numeric_limits<double>::epsilon(); //Initial Guess //Array<double,N1,1> y0 = Array<double,N1,1>::Constant(2); ArrayXd y0 = ArrayXd::Constant(N1,2); while ((y-y0).abs().matrix().maxCoeff() > deps) { // L.col(0) = Matrix<double,N1,1>::Constant(1); L.col(0) = VectorXd::Constant(N1,1); //Lp = Matrix<double,N1,1>::Zero(); Lp = VectorXd::Zero(N1); L.col(1) = y; for (int k=1; k!=N1; k++) { L.col(k+1) = ((2*k+1)*L.col(k).cwiseProduct(y.matrix())-k*L.col(k-1))/(k+1); } Lp = (N2)*(L.col(N0)-L.col(N1).cwiseProduct(y.matrix())).cwiseQuotient((1-y.square()).matrix()); y0 = y; y = y0-(L.col(N1).cwiseQuotient(Lp)).array(); } // Gauss Points //Matrix<double,N1,1> z = ((a*(1-y)+b*(1+y))/2).matrix(); VectorXd z(N1); z = ((a*(1-y)+b*(1+y))/2).matrix(); // Gauss Weights //Matrix<double,N1,1> w; VectorXd w(N1); w = (b-a)/(((1-y.square()).matrix()).cwiseProduct(Lp.cwiseProduct(Lp))).array()*pow((double)N2/N1,2); // Store //Matrix<double,N1,2> zw; Matrix<double,Dynamic,Dynamic> zw(N1,2); zw.col(0)=z; zw.col(1)=w; return zw; }