int main (int, char **) { Lattice L = SV(); L.relax(1e-14); L.tau = L.tau_rw(); L.optimize (cost_cp); H.L->info ("Modulus: tau = {}", L.tau); Pen p (Color(255,0,0),1,Color(255,255,0)); Figure F; vector<cpx> fd; fd.push_back(L(coo(1,1))); fd.push_back(L(coo(2,1))); fd.push_back(L(coo(2,2))); fd.push_back(L(coo(1,2))); F.add (std::make_unique <Polygon> (fd, Pen(0,0,200,true))); for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) for (unsigned k=0; k<L.n; ++k) F.add (std::make_unique <Circle> (L(coo(i,j),k), L.r[k], Pen(0,.2))); for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) for (unsigned k=0; k<L.n; ++k) for (unsigned l=0; l<L.adj[k].size(); ++l) F.add (std::make_unique <Segment> (L(coo(i,j),k), L(coo(i,j),k) + L.shift(k,l), Pen(0,.1))); F.show(); F.pause(); F.output_pdf(); return 0; }
int main (int argc, char ** argv) { H.init ("Test: circle packing", argc, argv, "s=4"); Map m (13); m << Edge(0,1) << Edge(0,3) << Edge(0,5) << Edge(1,2) << Edge(1,4) << Edge(1,6) << Edge(1,3) << Edge(1,0) << Edge(2,7) << Edge(2,4) << Edge(2,1) << Edge(3,0) << Edge(3,1) << Edge(3,6) << Edge(3,5) << Edge(4,1) << Edge(4,2) << Edge(4,7) << Edge(4,6) << Edge(5,0) << Edge(5,3) << Edge(5,6) << Edge(5,8) << Edge(5,10) << Edge(6,1) << Edge(6,4) << Edge(6,7) << Edge(6,9) << Edge(6,11) << Edge(6,8) << Edge(6,5) << Edge(6,3) << Edge(7,12) << Edge(7,9) << Edge(7,6) << Edge(7,4) << Edge(7,2) << Edge(8,5) << Edge(8,6) << Edge(8,11) << Edge(8,10) << Edge(9,6) << Edge(9,7) << Edge(9,12) << Edge(9,11) << Edge(10,5) << Edge(10,8) << Edge(10,11) << Edge(11,10) << Edge(11,8) << Edge(11,6) << Edge(11,9) << Edge(11,12) << Edge(12,11) << Edge(12,9) << Edge(12,7); for (int i=0; i<int(H['s']); ++i) m.barycentric(); m.inscribe(m.face(Edge(1,m.v[1]->adj.back()))); m.balance(); m.show(); Vector<double> x(3*m.n); double r = 1.0/sqrt(m.n); for (int i=0; i<m.n; ++i) { x[3*i] = m.v[i]->z.real() / (1-r); x[3*i+1] = m.v[i]->z.imag() / (1-r); x[3*i+2] = .8*r; } Minimizer<double> MM (3*m.n, [&m](const Vector<double> &x, Vector<double> &g) { return Map_fg_circle_disk (x,g,&m); }); MM.cb = cb; MM.minimize_qn (x); x = MM.x; std::cerr << "Number of vertices: " << m.n << std::endl; std::cerr << "Final value of f: " << MM.fx << std::endl; std::cerr << "Final square gradient: " << inner_prod(MM.gx,MM.gx) << std::endl; for (int i=0; i<m.n; ++i) { m.v[i]->z = cpx (x[3*i], x[3*i+1]); m.v[i]->r = x[3*i+2]; } Figure f; m.plot_circles(f); f.add (new Circle(cpx(0.0,0.0),1.0)); f.show(); f.pause(); f.output (); }
void OldPath::output_pdf (const std::string &s) const { int l=0; cpx z(0); std::vector<cpx> p(1); for (char i : *this) { l = (relative ? l+i : i) % 4; z += gsl::at(dzc,l); p.push_back(z); } Figure F; F.add (std::make_unique <Path> (p, Pen(0,.2))); F.output_pdf(s); }
void OldPath::output_pdf (const std::string &s) const { int l=0; cpx z(0); std::vector<cpx> p(1); for (char i : *this) { l = (relative ? l+i : i) % 4; z += dzc[l]; p.push_back(z); } Figure F; F.add (new Path(p, Pen(0,.2))); F.output_pdf(s); }