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

📅  最后修改于: 2021-10-23 09:12:00             🧑  作者: Mango

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

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

  • 检查是否 x >= 0 且 y >= 0 且 z >= 0,则 Point 位于第一个八分圆。
  • 检查 x < 0 和 y >= 0 和 z >= 0,然后点位于第二个八分圆。
  • 检查是否 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.
?>


Javascript


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