double width( const double * py, double threshold, size_t spos, size_t tpos, size_t epos ) { long xL = left_bound<double>( py, threshold, tpos, spos ); long xR = right_bound<double>( py, threshold, tpos, epos ); double Xl = left_intersection( py, xL, threshold ); double Xr = right_intersection( py, xR, threshold ); return Xr - Xl; }
double width( const double * py, double threshold, uint32_t spos, uint32_t tpos, size_t epos ) { int xL = left_bound<double>( py, threshold, tpos, spos ); int xR = right_bound<double>( py, threshold, tpos, epos ); Xl = left_intersection( py, xL, spos, threshold ); Xr = right_intersection( py, xR, epos, threshold ); return Xr - Xl; }
double centerX( const double * py, double threshold, size_t spos, size_t tpos, size_t epos ) { long xL = left_bound<double>( py, threshold, tpos, spos ); long xR = right_bound<double>( py, threshold, tpos, epos ); double Xl = left_intersection( py, xL, threshold ); double Xr = right_intersection( py, xR, threshold ); double x0 = fx_( xL - 1 ); double ma = 0; double ta = 0; double baseH = threshold; { // left triangle // // 90deg rotated triangle (h == time axis) // /| // / | h A = (1/2) a * h; // /__| Gy = (1/3) * h // a double h = fx_( xL ) - Xl; double a = py[xL] - baseH; double area = h * a / 2; double Gy = h / 3; double cx = fx_( xL ) - Gy - x0; ta += area; ma += area * cx; } { // right triangle double h = Xr - fx_( xR ); double a = py[xR] - baseH; double area = h * a / 2; double Gy = h / 3; double cx = fx_( xR ) + Gy - x0; ta += area; ma += area * cx; } //ta = aL + aR; //ma = mL + mR; for (long x = xL; x < xR; ++x) { // 90 deg rotated trapezium // c // ________ // / | A = (1/2) * (a + c) * h; // d / Gy | b = h h(a + 2c) // /_________| Gy = ------------ // a 3(a + c) // double h = fx_( x + 1 ) - fx_( x ); double a = py[x + 1] - baseH; double c = py[x] - baseH; double Gy = (h * (a + 2 * c)) / (3 * (a + c)); double area = (c + a) * h / 2; ta += area; double cx = ( fx_( x + 1 ) - Gy) - x0; ma += area * cx; }; double xc = ma / ta + x0; return xc; };