bool modify_compactness(float tC, bool up) { bool ret = true; //choose a random direction int ti = UnityEngine.Random.Range(0, 2); // stretch along x-axis if ti = 0 and along z-axis if ti = 1 Matrix4x4 tmp = Matrix4x4.identity; if (ti == 1) { tmp = Helper.get_rot_Y(90); } // see if it is stretching or compressing that would increase/decrease compactness float fct = 1.1f; double old_cmp = modified_obj.compactess(); modified_obj.modify_object(tmp, 0.9f); if ((modified_obj.compactess() > old_cmp && up) || (modified_obj.compactess() < old_cmp && !up)) { fct = 0.9f; } modified_obj.modify_object(tmp, 1.0f / 0.9f); //Now keep repeating stretch or compress until the derired compacntess is reached. int cntrLmt = 100, cntr = 0; while (((modified_obj.compactess() < tC && up) || ((modified_obj.compactess() > tC && !up))) && cntr < cntrLmt) { old_cmp = modified_obj.compactess(); modified_obj.modify_object(tmp, fct); //If the compactness starts decreasing then we need a new random polyhedron if ((modified_obj.compactess() <= old_cmp && up) || (modified_obj.compactess() >= old_cmp && !up)) { ret = false; break; } cntr++; } if (cntr >= cntrLmt) { ret = false; } return(ret); }
bool create_object(int isSym, int isCmp, float tSL, float tSH, float tCL, float tCH) { bool ret = true; m = new Model(); #region 1) Symmetric and Compact /* 1) ***************** Symmetric and Compact ******************/ if (isSym == 1 && isCmp == 1) { bool attempt_failed = true; int outCtr = 0, outCtrLmt = 100; do { m.regenerate(); modified_obj = m.generate_off_obj(); //The object is symmetric but if it is not compact if (modified_obj.compactess() < tCH) { attempt_failed = !modify_compactness(tCH, true); } outCtr++; } while (attempt_failed && outCtr < outCtrLmt); if (outCtr >= outCtrLmt) { ret = false; } } #endregion #region 2) Symmetric and in between Compact /* 2) ***************** Symmetric and in between Compact ******************/ if (isSym == 1 && isCmp == 0) { bool attempt_failed = true; int outCtr = 0, outCtrLmt = 100; do { m.regenerate(); modified_obj = m.generate_off_obj(); float df = (tCH - tCL); //The object is symmetric but if it is not compact if (modified_obj.compactess() < tCL) { float t = (float)Helper.get_random_double(tCL, tCH - (df / 4.0f)); attempt_failed = !modify_compactness(t, true); } //The object is symmetric but if it is compact else if (modified_obj.compactess() > tCH) { float t = (float)Helper.get_random_double(tCL + (df / 4.0f), tCH); attempt_failed = !modify_compactness(t, false); } outCtr++; } while (attempt_failed && outCtr < outCtrLmt); if (outCtr >= outCtrLmt) { ret = false; } } #endregion #region 3) Symmetric and Non-Compact /* 3) ***************** Symmetric and Non-Compact ******************/ if (isSym == 1 && isCmp == -1) { bool attempt_failed = true; int outCtr = 0, outCtrLmt = 100; do { m.regenerate(); modified_obj = m.generate_off_obj(); //The object is symmetric but if it is compact if (modified_obj.compactess() > tCL) { attempt_failed = !modify_compactness(tCL, false); } outCtr++; if (modified_obj.compactess() <= 0.11) { attempt_failed = true; } } while (attempt_failed && outCtr < outCtrLmt); if (outCtr >= outCtrLmt) { ret = false; } } #endregion #region 4) in between Symmetry and Compact /* 4) ***************** in between Symmetry and Compact ******************/ if (isSym == 0 && isCmp == 1) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; int ctr = 0, ctrLmt = 100; float df = (tSH - tSL); //first we create a highly compact object, a little more compact than was asked for. float nwTCH = tCH + 0.3f * tCH; do { m.regenerate(); modified_obj = m.generate_off_obj(); if (modified_obj.compactess() < nwTCH) { attempt_failed = !modify_compactness(nwTCH, true); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH) { float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * df / 4.0f); attempt_failed = !modify_symmetry(ll, tSH, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() >= tCH)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion #region 5) in between Symmetry and in between Compactness /* 5) ***************** in between Symmetry and in between Compactness ******************/ if (isSym == 0 && isCmp == 0) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; tot_attempt_success = true; int ctr = 0, ctrLmt = 100; float dfS = (tSH - tSL); //first we create a highly compact object, a little more compact than was asked for. do { m.regenerate(); modified_obj = m.generate_off_obj(); float dfC = (tCH - tCL); //The object is symmetric but if it is not compact if (modified_obj.compactess() < tCH) { //float t = (float)Helper.get_random_double(tCL + (dfC / 2.0f), tCH ); attempt_failed = !modify_compactness(tCH - dfC / 5.0f, true); } //The object is symmetric but if it is compact else if (modified_obj.compactess() > tCH) { //float t = (float)Helper.get_random_double(tCL + (dfC / 4.0f), tCH); attempt_failed = !modify_compactness(tCH - dfC / 5.0f, false); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH) { float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * dfS / 4.0f); attempt_failed = !modify_symmetry(ll, tSH, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() >= tCL) && (modified_obj.compactess() <= tCH)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion #region 6) in between Symmetry and not Compact /* 5) ***************** in between Symmetry and not Compact ******************/ if (isSym == 0 && isCmp == -1) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; tot_attempt_success = true; int ctr = 0, ctrLmt = 100; float dfS = (tSH - tSL); float dfC = (tCH - tCL); //first we create a non compact object. do { m.regenerate(); modified_obj = m.generate_off_obj(); float t = tCL; if (modified_obj.compactess() > t) { attempt_failed = !modify_compactness(t, false); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSL || modified_obj.degree_of_asymmetry() > tSH) { float ll = (float)Helper.get_random_double(tSL, tSL + 3.0 * dfS / 4.0f); attempt_failed = !modify_symmetry(ll, tSH, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSL) && (modified_obj.degree_of_asymmetry() <= tSH) && (modified_obj.compactess() <= tCL) && (modified_obj.compactess() >= 0.11)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion #region 7) Asymmetric and Compact /* 7) ***************** Asymmetric and Compact ******************/ if (isSym == -1 && isCmp == 1) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; tot_attempt_success = true; int ctr = 0, ctrLmt = 100; float df = (tSH - tSL); //first we create a highly compact object, a little more compact than was asked for. float nwTCH = tCH + 0.4f * tCH; do { m.regenerate(); modified_obj = m.generate_off_obj(); if (modified_obj.compactess() < nwTCH) { attempt_failed = !modify_compactness(nwTCH, true); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSH) { float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f); attempt_failed = !modify_symmetry(ll, 1.0f, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() >= tCH)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion #region 8) Asymmetric and in between Compact /* 7) ***************** Asymmetric and in between Compact ******************/ if (isSym == -1 && isCmp == 0) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; tot_attempt_success = true; int ctr = 0, ctrLmt = 100; float df = (tSH - tSL); //first we create a highly compact object, a little more compact than was asked for. float nwTCH = tCH + 0.4f * tCH; do { m.regenerate(); modified_obj = m.generate_off_obj(); float dfC = (tCH - tCL); //The object is symmetric but if it is not compact if (modified_obj.compactess() < tCH) { //float t = (float)Helper.get_random_double(tCL + (dfC / 2.0f), tCH ); attempt_failed = !modify_compactness(tCH, true); } //The object is symmetric but if it is compact else if (modified_obj.compactess() > tCH) { //float t = (float)Helper.get_random_double(tCL + (dfC / 4.0f), tCH); attempt_failed = !modify_compactness(tCH + dfC / 8.0f, false); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSH) { float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f); attempt_failed = !modify_symmetry(ll, 1.0f, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() >= tCL) && (modified_obj.compactess() <= tCH)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion #region 9) Asymmetric and non-Compact /* 7) ***************** Asymmetric and non-Compact ******************/ if (isSym == -1 && isCmp == -1) { bool isSat = false; int outOutCntr = 0, outOutCntrLmt = 100; do { int outCntr = 0, outCntrLmt = 100; bool tot_attempt_success = true; do { // First obtain desired compactness bool attempt_failed = true; tot_attempt_success = true; int ctr = 0, ctrLmt = 100; float df = (tSH - tSL); //first we create a highly compact object, a little more compact than was asked for. float nwTCH = tCH + 0.4f * tCH; do { m.regenerate(); modified_obj = m.generate_off_obj(); float t = tCL + (tCH - tCL) / 2; if (modified_obj.compactess() > t) { attempt_failed = !modify_compactness(t, false); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } // Now modify Assymettry if (tot_attempt_success) { attempt_failed = true; ctr = 0; ctrLmt = 100; Matrix4x4 tmp = Matrix4x4.identity; tmp[2, 0] = 0.1f; tmp[2, 1] = 0.1f; do { if (modified_obj.degree_of_asymmetry() < tSH) { float ll = (float)Helper.get_random_double(tSH, tSH + df / 4.0f); attempt_failed = !modify_symmetry(ll, 1.0f, tmp); } ctr++; } while (attempt_failed && ctr < ctrLmt); if (ctr >= ctrLmt) { tot_attempt_success = false; } } outCntr++; } while (!tot_attempt_success && outCntr < outCntrLmt); if ((modified_obj.degree_of_asymmetry() >= tSH) && (modified_obj.compactess() <= tCL) && (modified_obj.compactess() >= 0.11)) { isSat = true; } outOutCntr++; } while (outOutCntr < outOutCntrLmt && !isSat); ret = isSat; } #endregion return(ret); }