У меня есть линейные системы неравенств с 3 переменными, и я хотел бы построить эти области. В идеале мне бы хотелось что-то похожее на объекты в PolyhedronData. Я попробовал RegionPlot3D, но результаты визуально плохие и слишком многополигональные, чтобы вращаться в реальном времени.
Вот что я имею в виду: приведенный ниже код генерирует 10 наборов линейных ограничений и отображает их.
randomCons := Module[{}, hadamard = KroneckerProduct @@ Table[{{1, 1}, {1, -1}}, {3}]; invHad = Inverse[hadamard]; vs = Range[8]; m = mm /@ vs; sectionAnchors = Subsets[vs, {1, 7}]; randomSection := Mean[hadamard[[#]] & /@ #] & /@ Prepend[RandomChoice[sectionAnchors, 3], vs]; {p0, p1, p2, p3} = randomSection; section = Thread[m -> p0 + {x, y, z}.Orthogonalize[{p1 - p0, p2 - p0, p3 - p0}]]; And @@ Thread[invHad.m >= 0 /. section] ]; Table[RegionPlot3D @@ {randomCons, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}}, {10}]
Какие-либо предложения?
Обновление. Включив приведенные ниже предложения, вот версия, которую я в итоге использовал для построения допустимой области системы линейных неравенств.
(* Plots feasible region of a linear program in 3 variables, \ specified as cons[[1]]>=0,cons[[2]]>=0,... Each element of cons must \ be an expression of variables x,y,z only *) plotFeasible3D[cons_] := Module[{maxVerts = 20, vcons, vertCons, polyCons}, (* find intersections of all triples of planes and get rid of \ intersections that aren't points *) vcons = Thread[# == 0] & /@ Subsets[cons, {3}]; vcons = Select[vcons, Length[Reduce[#]] == 3 &]; (* Combine vertex constraints with inequality constraints and find \ up to maxVerts feasible points *) vertCons = Or @@ (And @@@ vcons); polyCons = And @@ Thread[cons >= 0]; verts = {x, y, z} /. FindInstance[polyCons && vertCons, {x, y, z}, maxVerts]; ComputationalGeometry`Methods`ConvexHull3D[verts, Graphics`Mesh`FlatFaces -> False] ]
Код для тестирования
randomCons := Module[{}, hadamard = KroneckerProduct @@ Table[{{1, 1}, {1, -1}}, {3}]; invHad = Inverse[hadamard]; vs = Range[8]; m = mm /@ vs; sectionAnchors = Subsets[vs, {1, 7}]; randomSection := Mean[hadamard[[#]] & /@ #] & /@ Prepend[RandomChoice[sectionAnchors, 3], vs]; {p0, p1, p2, p3} = randomSection; section = Thread[m -> p0 + {x, y, z}.Orthogonalize[{p1 - p0, p2 - p0, p3 - p0}]]; And @@ Thread[invHad.m >= 0 /. section] ]; Table[plotFeasible3D[List @@ randomCons[[All, 1]]], {50}];