void polyvertex::subdivide(int depth) { std::vector<edge_t> edges; do { edges = convexhull(vertices).construct_hull().second; for (std::vector<edge_t>::const_iterator it = edges.begin(); it != edges.end(); ++it) { vertices.push_back((vertices[std::get<0>(*it)] + vertices[std::get<1>(*it)]).normalized()); } } while (--depth != 0); }
int main() { vector<P> v; v.PB(MP(0, 1)); v.PB(MP(1, 2)); v.PB(MP(3, 2)); v.PB(MP(2, 1)); v.PB(MP(3, 1)); v.PB(MP(6, 3)); v.PB(MP(7, 0)); vector<P> w = convexhull(v); } // resultado: (0,1) (7,0) (6,3) (1,2)
void polyvertex::subdivide(int depth) { std::vector<edge_t> edges; int a, b; do { edges = convexhull(vertices).construct().second; for (std::vector<edge_t>::const_iterator it = edges.begin(); it != edges.end(); ++it) { std::tie(a, b) = *it; vertices.push_back((vertices[a] + vertices[b]).normalize()); } } while (--depth != 0); }
void brute(int ix) { int mask,i,best=0; /* mask of trees to cut, 1:cut */ for(mask=0;mask<(1<<N);mask++) if(!(mask&(1<<ix))) { for(n=i=0;i<N;i++) if(!(mask&(1<<i))) p[n].x=px[i],p[n++].y=py[i]; if(best>=n) continue; if(n>3) { convexhull(); for(i=0;i<hn;i++) if(h[i].x==px[ix] && h[i].y==py[ix]) { best=n; break; } } else best=n; } printf("%d\n",N-best); }
void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shift) { if (!m_sample) return; InputGeom* geom = m_sample->getInputGeom(); if (!geom) return; if (shift) { // Delete int nearestIndex = -1; const ConvexVolume* vols = geom->getConvexVolumes(); for (int i = 0; i < geom->getConvexVolumeCount(); ++i) { if (pointInPoly(vols[i].nverts, vols[i].verts, p) && p[1] >= vols[i].hmin && p[1] <= vols[i].hmax) { nearestIndex = i; } } // If end point close enough, delete it. if (nearestIndex != -1) { geom->deleteConvexVolume(nearestIndex); } } else { // Create // If clicked on that last pt, create the shape. if (m_npts && rcVdistSqr(p, &m_pts[(m_npts-1)*3]) < rcSqr(0.2f)) { if (m_nhull > 2) { // Create shape. float verts[MAX_PTS*3]; for (int i = 0; i < m_nhull; ++i) rcVcopy(&verts[i*3], &m_pts[m_hull[i]*3]); float minh = FLT_MAX, maxh = 0; for (int i = 0; i < m_nhull; ++i) minh = rcMin(minh, verts[i*3+1]); minh -= m_boxDescent; maxh = minh + m_boxHeight; geom->addConvexVolume(verts, m_nhull, minh, maxh, (unsigned char)m_areaType); } m_npts = 0; m_nhull = 0; } else { // Add new point if (m_npts < MAX_PTS) { rcVcopy(&m_pts[m_npts*3], p); m_npts++; // Update hull. if (m_npts > 1) m_nhull = convexhull(m_pts, m_npts, m_hull); else m_nhull = 0; } } } }