📜  确定轴向平面八分圆的程序

📅  最后修改于: 2021-04-24 04:33:29             🧑  作者: Mango

给定3个坐标x,y和z,任务是确定轴向平面的八分圆。

例子:

方法:下面给出了确定轴向平面的八分圆需要检查的条件。

  • 检查x> = 0且y> = 0且z> = 0,则Point位于第一个八进制数。
  • 检验x <0且y> = 0且z> = 0,则Point位于第二个八分圆。
  • 检查x <0和y <0以及z> = 0,则Point位于第三个八分位。
  • 检查x> = 0且y <0和z> = 0,则Point位于第4个八分圆。
  • 检查x> = 0且y> = 0且z <0,则Point位于第5个八分圆。
  • 检查x <0且y> = 0且z <0,则Point位于第6个八分圆。
  • 检查x <0和y <0以及z <0,则Point位于第7个八分位。
  • 检查x> = 0且y <0和z <0,则Point位于第8个八分圆。

下面是上述方法的实现:

C++
// C++ program to print octant 
// of a given point.
#include  
#include
  
using namespace std;
  
// Function to print octant
void octant(float x, float y,
                     float z)
{
    if (x >= 0 && y >= 0 && z >= 0)
        cout << "Point lies in 1st octant\n";
           
    else if (x < 0 && y >= 0 && z >= 0)
        cout << "Point lies in 2nd octant\n";
           
    else if (x < 0 && y < 0 && z >= 0)
        cout << "Point lies in 3rd octant\n";
           
    else if (x >= 0 && y < 0 && z >= 0)
        cout << "Point lies in 4th octant\n";
           
    else if (x >= 0 && y >= 0 && z < 0)
        cout << "Point lies in 5th octant\n";
           
    else if (x < 0 && y >= 0 && z < 0)
        cout << "Point lies in 6th octant\n";
           
    else if (x < 0 && y < 0 && z < 0)
        cout << "Point lies in 7th octant\n";
           
    else if (x >= 0 && y < 0 && z < 0)
        cout << "Point lies in 8th octant\n";
}
  
// Driver Code 
int main()
{
    float x = 2, y = 3, z = 4;
    octant(x, y, z) ;
   
    x = -4, y = 2, z = -8;
    octant(x, y, z);
   
    x = -6, y = -2, z = 8;
    octant(x, y, z);
    return 0;
}
// This code is contributed 
// by Amber_Saxena.


C
// C program to print octant 
// of a given point.
#include 
  
// Function to print octant
void octant(float x, float y,
                     float z)
{
    if (x >= 0 && y >= 0 && z >= 0)
        printf("Point lies in 1st octant\n");
          
    else if (x < 0 && y >= 0 && z >= 0)
        printf("Point lies in 2nd octant\n");
          
    else if (x < 0 && y < 0 && z >= 0)
        printf("Point lies in 3rd octant\n");
          
    else if (x >= 0 && y < 0 && z >= 0)
        printf("Point lies in 4th octant\n");
          
    else if (x >= 0 && y >= 0 && z < 0)
        printf("Point lies in 5th octant\n");
          
    else if (x < 0 && y >= 0 && z < 0)
        printf("Point lies in 6th octant\n");
          
    else if (x < 0 && y < 0 && z < 0)
        printf("Point lies in 7th octant\n");
          
    else if (x >= 0 && y < 0 && z < 0)
        printf("Point lies in 8th octant\n");
}
  
// Driver Code
int main()
{
    float x = 2, y = 3, z = 4;
    octant(x, y, z) ;
  
    x = -4, y = 2, z = -8;
    octant(x, y, z);
  
    x = -6, y = -2, z = 8;
    octant(x, y, z);
}
  
// This code is contributed 
// by Amber_Saxena.


Java
// Java program to print octant 
// of a given point.
import java.util.*;
  
class solution
{
  
// Function to print octant
static void octant(float x, float y,
                    float z)
{
    if (x >= 0 && y >= 0 && z >= 0)
        System.out.println("Point lies in 1st octant");
          
    else if (x < 0 && y >= 0 && z >= 0)
        System.out.println("Point lies in 2nd octant");
          
    else if (x < 0 && y < 0 && z >= 0)
    System.out.println("Point lies in 3rd octant");
          
    else if (x >= 0 && y < 0 && z >= 0)
        System.out.println("Point lies in 4th octant");
          
    else if (x >= 0 && y >= 0 && z < 0)
        System.out.println("Point lies in 5th octant");
          
    else if (x < 0 && y >= 0 && z < 0)
        System.out.println("Point lies in 6th octant");
          
    else if (x < 0 && y < 0 && z < 0)
        System.out.println("Point lies in 7th octant");
          
    else if (x >= 0 && y < 0 && z < 0)
    System.out.println("Point lies in 8th octant");
}
  
// Driver Code 
public static void main(String args[])
{
    float x = 2, y = 3, z = 4;
    octant(x, y, z) ;
  
    x = -4; y = 2; z = -8;
    octant(x, y, z);
  
    x = -6; y = -2; z = 8;
    octant(x, y, z);
  
}
}
//This code is contributed by Surendra_Gangwar


Python
# Python program to print octant of a 
# given point.
  
# Function to print octant
def octant(x, y, z): 
      
    if x >= 0 and y >= 0 and z >= 0:
        print "Point lies in 1st octant"
          
    elif x < 0 and y >= 0 and z >= 0:
        print "Point lies in 2nd octant"
          
    elif x < 0 and y < 0 and z >= 0:
        print "Point lies in 3rd octant"
          
    elif x >= 0 and y < 0 and z >= 0:
        print "Point lies in 4th octant"
          
    elif x >= 0 and y >= 0 and z < 0:
        print "Point lies in 5th octant"
          
    elif x < 0 and y >= 0 and z < 0:
        print "Point lies in 6th octant"
          
    elif x < 0 and y < 0 and z < 0:
        print "Point lies in 7th octant"
          
    elif x >= 0 and y < 0 and z < 0:
        print "Point lies in 8th octant"
              
  
# Driver Code 
x, y, z = 2, 3, 4
octant(x, y, z) 
  
x, y, z = -4, 2, -8
octant(x, y, z) 
  
x, y, z = -6, -2, 8
octant(x, y, z)


C#
// C# program to print octant 
// of a given point.
using System;
  
class GFG
{
      
// Function to print octant 
static void octant(float x, float y, 
                   float z) 
{ 
    if (x >= 0 && y >= 0 && z >= 0) 
        Console.WriteLine("Point lies in 1st octant"); 
          
    else if (x < 0 && y >= 0 && z >= 0) 
        Console.WriteLine("Point lies in 2nd octant"); 
          
    else if (x < 0 && y < 0 && z >= 0) 
        Console.WriteLine("Point lies in 3rd octant"); 
          
    else if (x >= 0 && y < 0 && z >= 0) 
        Console.WriteLine("Point lies in 4th octant"); 
          
    else if (x >= 0 && y >= 0 && z < 0) 
        Console.WriteLine("Point lies in 5th octant"); 
          
    else if (x < 0 && y >= 0 && z < 0) 
        Console.WriteLine("Point lies in 6th octant"); 
          
    else if (x < 0 && y < 0 && z < 0) 
        Console.WriteLine("Point lies in 7th octant"); 
          
    else if (x >= 0 && y < 0 && z < 0) 
    Console.WriteLine("Point lies in 8th octant"); 
} 
  
// Driver Code 
static public void Main ()
{
    float x = 2, y = 3, z = 4; 
    octant(x, y, z) ; 
  
    x = -4; y = 2; z = -8; 
    octant(x, y, z); 
      
    x = -6; y = -2; z = 8; 
    octant(x, y, z); 
} 
} 
  
// This code is contributed by ajit


PHP
= 0 && $y >= 0 && $z >= 0)
        echo "Point lies in 1st octant\n";
           
    else if ($x < 0 && $y >= 0 && $z >= 0)
        echo "Point lies in 2nd octant\n";
           
    else if ($x < 0 && $y < 0 && $z >= 0)
        echo "Point lies in 3rd octant\n";
           
    else if ($x >= 0 && $y < 0 && $z >= 0)
        echo "Point lies in 4th octant\n";
           
    else if ($x >= 0 && $y >= 0 && $z < 0)
        echo "Point lies in 5th octant\n";
           
    else if ($x < 0 && $y >= 0 && $z < 0)
        echo "Point lies in 6th octant\n";
           
    else if ($x < 0 && $y < 0 && $z < 0)
        echo "Point lies in 7th octant\n";
           
    else if ($x >= 0 && $y < 0 && $z < 0)
        echo "Point lies in 8th octant\n";
} 
    
// Driver Code 
$x = 2;
$y = 3;
$z = 4;
octant($x, $y, $z) ;
   
$x = -4;
$y = 2;
$z = -8;
octant($x, $y, $z);
   
$x = -6;
$y = -2;
$z = 8;
octant($x, $y, $z);
    
// This code is contributed 
// by Amber_Saxena.
?>


输出:
Point lies in 1st octant
Point lies in 6th octant
Point lies in 3rd octant