📌  相关文章
📜  检查是否可以绘制具有给定方向余弦的直线

📅  最后修改于: 2021-04-21 21:40:17             🧑  作者: Mango

给定3-D平面的三个方向余弦lmn ,任务是检查是否可以用它们绘制一条直线。打印如果可能的话其他打印

例子:

方法:如果与正X轴,角度b与正Y轴和角度c。与正Z轴的直线形式的角度则其方向余弦是COS的(a),COS(B)cos(c)中
对于一条直线, cos 2 (a)+ cos 2 (b)+ cos 2 (c)= 1

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
  
// Function that returns true
// if a straight line is possible
bool isPossible(float x, float y, float z)
{
    float a = x * x + y * y + z * z;
    if (ceil(a) == 1 && floor(a) == 1)
        return true;
    return false;
}
  
// Driver code
int main()
{
    float l = 0.70710678, m = 0.5, n = 0.5;
  
    if (isPossible(l, m, n))
        cout << "Yes";
    else
        cout << "No";
  
    return 0;
}


Java
// Java implementation of the approach
import java.util.*;
  
class GFG
{
  
// Function that returns true
// if a straight line is possible
static boolean isPossible(float x, float y, float z)
{
    float a = x * x + y * y + z * z;
    if (Math.ceil(a) == 1 && Math.floor(a) == 1)
        return true;
    return false;
}
  
// Driver code
public static void main(String args[])
{
    float l = 0.70710678f, m = 0.5f, n = 0.5f;
  
    if (isPossible(l, m, n))
        System.out.println("Yes");
    else
        System.out.println("No");
}
}
  
// This code is contributed by
// Shashank_Sharma


Python3
# Python3 implementation of the approach 
from math import ceil, floor
  
# Function that returns true 
# if a straight line is possible 
def isPossible(x, y, z) :
  
    a = x * x + y * y + z * z
    a = round(a, 8)
      
    if (ceil(a) == 1 & floor(a) == 1) :
        return True
    return False
  
# Driver code 
if __name__ == "__main__" :
      
    l = 0.70710678
    m = 0.5
    n = 0.5
  
    if (isPossible(l, m, n)): 
        print("Yes") 
    else :
        print("No")
  
# This code is contributed by Ryuga


C#
// C# implementation of the approach
using System;
  
class GFG
{
  
// Function that returns true
// if a straight line is possible
static bool isPossible(float x, float y, float z)
{
    float a = x * x + y * y + z * z;
    if (Math.Ceiling(a) == 1 && Math.Floor(a) == 1)
        return true;
    return false;
}
  
// Driver code
public static void Main()
{
    float l = 0.70710678f, m = 0.5f, n = 0.5f;
    if (isPossible(l, m, n))
        Console.WriteLine("Yes");
    else
        Console.WriteLine("No");
}
}
  
// This code is contributed by Ita_c.


PHP


输出:
Yes