/* Generate a random simple polygon inside a rectangle vert is number of vertices (>= 3) width, height are dimensions of rectangle spacing (0 - 1 inclusive) determines random spacing along circle sharpness (0 - 1 inclusive) determines how spiky polygon will be */ Polygon poly_mutator::randSimplePoly(const float spacing, const float sharpness) { // get center of poly close to rectangle center with padding from edge const int cenX = static_cast<int>((width / 2) + (randNorm() * width / 3)); const int cenY = static_cast<int>((height / 2) + (randNorm() * height / 3)); // polygon vertices Polygon::Container v; v.reserve(vertCount); Point p; // begin generating vertices const float radInc = 2 * PI / vertCount; float rad = randUni() * 2 * PI; for (int vert = 0; vert < vertCount; ++vert, rad += radInc) { float radRand = rad + radInc * randNorm() / 2.1 * spacing; std::pair<float, float> intPoint = getPos(cenX, cenY, radRand, width, height); // vector from center to intersection float vx = intPoint.first - static_cast<float>(cenX); float vy = intPoint.second - static_cast<float>(cenY); // delta from center float vMult = randNorm(); float dx = (vx / 2) * (1.0 + vMult * sharpness); float dy = (vy / 2) * (1.0 + vMult * sharpness); p.x = static_cast<int>(cenX + dx); p.y = static_cast<int>(cenY + dy); v.push_back(p); } return Polygon(v); }
std::vector<double> directionPerturbation(const std::vector<double> &oVec, double maxRadius, double pNorm) { // project on the k-1 simplex std::vector<double> newObjVec(oVec); toUnitVec(newObjVec, 1.0); // calculate the p-distance double dist = magnitudeP(oVec, pNorm); // perturb within a sphere with r=maxRadius double s = 0.0; for(int i=0; i<newObjVec.size(); i++) { double rd = (randUni() * 2.0 -1.0) * sqrt(maxRadius*maxRadius - s); s += pow(rd, 2.0); newObjVec[i] += rd; } // project on the p-norm unit sphere toUnitVec(newObjVec, pNorm); //scale back scale(newObjVec, dist); return newObjVec; }
void ArrayTest::fill_array( int /*test_case_idx*/, int i, int j, Mat& arr ) { if( i == REF_INPUT_OUTPUT ) cvtest::copy( test_mat[INPUT_OUTPUT][j], arr, Mat() ); else if( i == INPUT || i == INPUT_OUTPUT || i == MASK ) { Scalar low, high; get_minmax_bounds( i, j, arr.type(), low, high ); randUni( ts->get_rng(), arr, low, high ); } }