private IneqTree IneqTreeCylinders1(int count, double R, double r) { IneqTree res = new IneqTree((x, y, z) => 1); for (int i = 0; i < count; i++) { double x0 = Math.Cos(i * 2 * Math.PI / count); double y0 = Math.Sin(i * 2 * Math.PI / count); res = res | (IneqTree)(((x, y, z) => { double vp = x * x0 + y * y0; return(vp < 0 ? 1 : (x - vp * x0) * (x - vp * x0) + (y - vp * y0) * (y - vp * y0) + z * z - r * r); }) & (IneqTree) ((x, y, z) => { double vp = x * x0 + y * y0; return(-vp + R); } )); } return(res); }
public static IneqTree FromFormula(string formulaText) { error = false; IneqTree result = null; try { result = BuildIneqTree(formulaText .Replace("&&", "&") .Replace("||", "|") .Replace(" ", "") .Replace("\n", "") .Replace("\r", "") .Replace("\t", "") .Replace(",", ".")); } catch (Exception exc) { if (!error) { throw exc; } } if (error) { throw new Exception("Syntax error in expression"); } return(result); }
private IneqTree IneqTreePlanes1(int count) { IneqTree res = new IneqTree((x, y, z) => - 1); for (int i = 0; i < count; i++) { double x0 = 0.75d * Math.Cos(i * 2 * Math.PI / count); double y0 = 0.75d * Math.Sin(i * 2 * Math.PI / count); double z0 = 0; res = res & ((x, y, z) => (x - x0) * x0 + (y - y0) * y0 + (z - z0) * 0.5); } return(res); }
private IneqTree IneqTreeCylinders(int count, double R, double r) { IneqTree res = new IneqTree((x, y, z) => 1); for (int i = 0; i < count; i++) { double x0 = R * Math.Cos(i * 2 * Math.PI / count); double y0 = R * Math.Sin(i * 2 * Math.PI / count); res = res | ((x, y, z) => (x - x0) * (x - x0) + (y - y0) * (y - y0) - r * r); } return(res); }
private IneqTree IneqTreeAnuloids(int count, double z0, double z1, double r0, double r1, double R0, double R1) { IneqTree res = new IneqTree((x, y, z) => 1); for (int i = 0; i < count; i++) { double z = z0 + i * (z1 - z0) / (count - 1); double r = r0 + i * (r1 - r0) / (count - 1); double R = R0 + i * (R1 - R0) / (count - 1); res = res | IneqTreeAnuloid(0, 0, z, r, R, 0, 0, 1); } return(res); }
private IneqTree IneqTreeAntiAnuloids(int count, double RR, double R, double r) { IneqTree res = new IneqTree((x, y, z) => - 1); for (int i = 0; i < count; i++) { double rx = Math.Cos(i * 2 * Math.PI / count); double ry = Math.Sin(i * 2 * Math.PI / count); double x0 = RR * rx; double y0 = RR * ry; res = res & IneqTreeAnuloid(x0, y0, 0, r, R, -ry, rx, 0, true); } return(res); }
private static IneqTree BuildIneqTree(string vyraz) { int i, pocet_zavorek = 0, pozice_operatoru = -1; bool nasel_se_and = false; bool nasel_se_or = false; bool nasla_se_ner = false; char z; // zkoumany znak retezce IneqTree vysledek = null, node_levy = null, node_pravy = null; error = error || (vyraz.Length == 0); if (!error) { i = 0; while ((i < vyraz.Length) && (!nasel_se_or)) { z = vyraz[i]; if (z == '(') { pocet_zavorek++; } else if (z == ')') { pocet_zavorek--; } else if (pocet_zavorek == 0) { //budu zkoumat, jestli se nenasel zajimavy logicky operator nebo nerovnost if (z == '|') { // nasel se OR, zapamatuji si kde a cyklus skonci nasel_se_or = true; pozice_operatoru = i; } else if (!nasel_se_and) // jestli se uz nejake AND naslo, tak uz me zajima jenom pripadne nasledne OR { if (z == '&') { // nasel se prvni and, zapamatuji si kde a budu hledat dal, jestli tam treba neni or pozice_operatoru = i; nasel_se_and = true; } else if (!nasla_se_ner) // naslo-li se nejake < nebo >, hledam uz jenom logicke operatory { if ((z == '<') || (z == '>')) { pozice_operatoru = i; nasla_se_ner = true; } } // if (!nasla_se_ner) } // if (!nasel_se_and) } // if (pocet_zavorek==0) i++; } // while if (pocet_zavorek != 0) // je to blbe, nesouhlasi pocet zavorek { error = true; } else if (nasel_se_or) { // vytvorim uzel a rozdelim retezec a pustim na jeho casti stromovac string levy = vyraz.Substring(0, pozice_operatoru); string pravy = vyraz.Substring(pozice_operatoru + 1, vyraz.Length - pozice_operatoru - 1); node_levy = BuildIneqTree(levy); node_pravy = BuildIneqTree(pravy); vysledek = new IneqTree(IneqTree.NodeType.NodeOr, node_levy, node_pravy); } else if (nasel_se_and) { // dtto string levy = vyraz.Substring(0, pozice_operatoru); string pravy = vyraz.Substring(pozice_operatoru + 1, vyraz.Length - pozice_operatoru - 1); node_levy = BuildIneqTree(levy); node_pravy = BuildIneqTree(pravy); vysledek = new IneqTree(IneqTree.NodeType.NodeAnd, node_levy, node_pravy); } else if (nasla_se_ner) { // upravim nerovnost, ukoncim vetev, ulozim retezec PrepareFormula(ref vyraz, pozice_operatoru); engine.AddFunction("exp", (Func <double, double>)((a) => Math.Exp(a))); Func <double, double, double, double> formula = (Func <double, double, double, double>)engine.Formula(vyraz) .Parameter("x", DataType.FloatingPoint) .Parameter("y", DataType.FloatingPoint) .Parameter("z", DataType.FloatingPoint) .Result(DataType.FloatingPoint) .Build(); double testEval = formula(0, 0, 0); vysledek = new IneqTree(formula); } else // vsechny zavorky jsou zavrene, ale nenasel se operator { // mohou nastat dve moznosti: jsou tam zavorky navic nebo je to blbe if ((vyraz[0] == '(') && (vyraz[vyraz.Length - 1] == ')')) { string kratsi = vyraz.Substring(1, vyraz.Length - 2); vysledek = BuildIneqTree(kratsi); } else { error = true; } } // nenasel se operator } // if ( !error ) return(vysledek); } // funkce