ucs4string Segmentation::Segment(const ucs4string& ustr) { SegmentData data; DoSegment(ucs4string(), 1.0, ustr, data); if (data.m_res.empty()) return ustr; return data.m_res; }
void Segmentation::DoSegment(ucs4string base, double base_rr, ucs4string to_seg, SegmentData& data) { for (size_t i=1; i<to_seg.size(); ++i) { ucs4string us = to_seg.substr(0, i); DoSegment(base + ucs4_t(' ') + us, base_rr*GetRateReciprocal(us), to_seg.substr(i), data); } double rr = base_rr*GetRateReciprocal(to_seg); if (rr > data.m_rr) return; data.m_rr = rr; data.m_res = base + ucs4_t(' ') + to_seg; }
void DoEllipse(void) { int i,ibeg,iend; double dist_beg,dist_end,V0,ta,da,length,Time0,Time1,MaxAp,MaxVp,angle; Time0=Time_sec(); // first compute total length of path and build tables of info length = ArcLength(ThetaStart,ThetaEnd,MAXN); Time1=Time_sec(); printf("Length = %.9f Compute Time %.0f us\n",length, (Time1-Time0)*1e6); // time to achieve max vel ta = MaxV/MaxA; // dist to achieve max vel da = (0.5 * MaxA * ta) * ta; printf("Accel Time %f Accel dist %f\n",ta,da); // first move from where we are to starting point on ellipse x0=ch0->Dest; // starting point is where we currently are y0=ch1->Dest; z0=ch2->Dest; a0=ch3->Dest; x1 = pointx[0]*RESX; y1 = pointy[0]*RESY; z1=z0; // keep z and a the same a1=a0; DoLinear(); // now rotate knife to be at the right angle for the first segment angle = FindAngle(pointx[1]-pointx[0],pointy[1]-pointy[0]); printf("angle=%f %f %f\n",angle,pointx[1]-pointx[0],pointy[1]-pointy[0]); x0=x1; // xyz doesn't move y0=y1; z0=z1; a0=a1; a1=angle*RESA; // rotate knife to proper angle DoLinear(); // search to find segments needed to accellerate/decelerate // searches forward and backward throug the segments simultaneously // until either the begiining and ending are sufficient to accel/deccel // or we meet in the middle and run out of distance ibeg=0; iend=MAXN; dist_beg = dist_end = 0.0; do { if (dist_beg < dist_end) ibeg++; else iend--; dist_beg = sum[ibeg]; dist_end = sum[MAXN]-sum[iend]; // printf("ibeg=%d iend=%d dist beg %.3f dist_end %.3f\n",ibeg,iend,dist_beg,dist_end); } while ((dist_beg<da || dist_end<da) && ibeg<iend); // if distance available is less than required accel distance // then reduce the max velocity to what is achievable if (ibeg>=iend) { if (dist_beg<dist_end) MaxVp=sqrt(2.0*MaxA*dist_beg); else MaxVp=sqrt(2.0*MaxA*dist_end); } else { MaxVp=MaxV; } // adjust the acceleration to accelerate in exactly the beginning distance MaxAp = 0.5*MaxVp*MaxVp/dist_beg; // create all the segments f=fopen("C:\\temp\\kflopdata.txt","wt"); V0=0.0; // start from stop for (i=1;i<=ibeg;i++) DoSegment(i,&V0,MaxAp); // accel segments for (;i<=iend;i++) DoSegment(i,&V0,0.0); // constant velocity // adjust the acceleration to accelerate in exactly the ending distance MaxAp = 0.5*MaxVp*MaxVp/dist_end; for (;i<=MAXN;i++) DoSegment(i,&V0,-MaxAp); // decel segments fclose(f); }