S
S
Sergei Gribok2016-09-07 19:27:36
Algorithms
Sergei Gribok, 2016-09-07 19:27:36

Does a point belong to an octant?

The task is to write a program to determine whether a point belongs to an octant. An octant is a quarter in three dimensions. Everything is quite simple if it were not necessary to write a program that would do this with the help of only three atomic conditions (A condition on which it is impossible to further decompose. That is, a condition that can no longer be decomposed. Without logical operators.).
The maximum was done with the help of seven.

if (x>0)
   if (y>0)
      if (z>0)
         k = 1;
      else
         k = 8;
   else if (z>0)
       k = 4;
       else
       k = 5;
 else if (y>0)
      if (z>0)
          k = 2;
      else
          k = 7;
    else if (z>0)
          k = 3;
          else
          k = 6;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dom1n1k, 2016-09-07
@dom1n1k

The first thing that comes to mind (this is not ready-to-use code, but just a demonstration of the idea):

k = 0;
k |= x > 0 ? 0x1 : 0;
k |= y > 0 ? 0x2 : 0;
k |= z > 0 ? 0x4 : 0;

U
uvelichitel, 2016-09-07
@uvelichitel

Something like

k=1
if (y<0)
  k = 2;
if (z<0)
  k = 5 - k;
if (x<o)
  k = k + 4;

numbering of octants from one

S
Sumor, 2016-09-08
@Sumor

More or less like this:
The numbering does not match the one proposed in the link, but points from the same octant will be mapped to one number from 0 to 7.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question