Answer the question
In order to leave comments, you need to log in
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
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;
Something like
k=1
if (y<0)
k = 2;
if (z<0)
k = 5 - k;
if (x<o)
k = k + 4;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question