2

I'd like to find a vertexes of objects, which is determined by some equations. For example.

Eq1:   2x + y +  z <= 12;
Eq2:    x + y      >= 23;
Eq3:    x + y +  z <= 10;

And it's limited by

x >= 0
y >= 0
z => 0

And it gives a hexahedron. I want to know positions of vertexes, which this object is created from.

Is the only way to do this is to make a code that will check all possible variations of this equations?

array = array with this equations (6 elements)

for( i = 1; i <= array.lenght; i++ ){
 for( j = 1; j <= array.lenght; j++ ){
  for( k = 1; k <= array.lenght; k++ ){
    //and there check is solve of a variation is possible
  }   
 }    
}
Pavvi
  • 73
  • 11
  • Since these are 6 planes, the intersection of any 2 of them will be a line. So what do you mean by "vertexes"? – NonlinearFruit Mar 13 '16 at 21:13
  • when you say "code that checks all possible variations", do you mean that it calculates whether there is a solution for "all possible" values of x, y and z y iterating through the values? If so this is possible for small extents of x, y and z (given that they are constrained to >=0 and all equations only add) but impossible if you want to consider real numbers in the solution. – Richard Hodges Mar 13 '16 at 21:53
  • @NonlinearFruit - The vertices are the points at which three planes intersect. A hexahedron (e.g., a cube) has eight vertices. – Ted Hopp Mar 14 '16 at 03:08

1 Answers1

3

This is known as the vertex enumeration problem: to convert a polyhedron from a half-space representation (which is what you have—a set of inequalities) to a vertex representation. There are a number of algorithms in the literature for doing this efficiently in the general case. If you need to be as efficient as possible, you should look into one of these algorithms.

But with only six half-spaces known to form a bounded, non-degenerate hexahedron, brute force is probably just fine. Every vertex is at the intersection of three faces. Therefore, take each subset of three inequalities and compute the intersection point of the corresponding equations. (See below for how to do this.) If the intersection does not exist (e.g., two of the planes are parallel) or if the intersection point fails to satisfy any of the other three inequalities, then those three facets do not meet at a vertex; otherwise the point is one of the vertices. Repeat for each of the 6C3 = 20 combinations and you should end up with eight vertices.

To compute the intersection point of three inequalities, you can use some simple linear algebra. Take any three inequalities, for example:

2x +  y +  z <= 12
 x +  y      >= 23
 x           >= 0

Write them as a matrix equation:

┌             ┐┌   ┐   ┌    ┐
│ 2    1    1 ││ x │   │ 12 │
│             ││   │   │    │
│ 1    1    0 ││ y │ = │ 23 │
│             ││   │   │    │
│ 1    0    0 ││ z │   │  0 │
└             ┘└   ┘   └    ┘

(The matrix rows are the coefficients of x, y, and z in each inequality.) If the matrix on the left is singular (i.e., the determinant is zero), there's no common intersection point. Otherwise, compute the solution by inverting the matrix:

┌   ┐   ┌             ┐-1┌    ┐
│ x │   │ 2    1    1 │  │ 12 │
│   │   │             │  │    │
│ y │ = │ 1    1    0 │  │ 23 │
│   │   │             │  │    │
│ z │   │ 1    0    0 │  │  0 │
└   ┘   └             ┘  └    ┘

Any linear algebra library should be able to do this calculation for you, or—since this is 3D—you can use Cramer's Rule. Then check [x y z] against the other three inequalities to determine if it is a vertex.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521