
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if it is possible to draw a straight line with the given direction cosines in Python
Suppose we have three direction cosines l, m and n in 3-D space, we have to check whether it is possible to draw a straight line with these direction cosines or not.
So, if the input is like l = 0.42426 m = 0.56568 n = 0.7071, then the output will be True as this the direction cosines of a vector {3, 4, 5}.
To solve this, we will follow some rule as
- l = cos(a), where a is angle between the straight line and x-axis
- m = cos(b), where b is angle between the straight line and y-axis
- n = cos(c), where c is angle between the straight line and z-axis
- l^2 + m^2 + n^2 = 1
To solve this, we will follow these steps −
- angle := l * l + m * m + n * n
- angle := round of the value of angle up to 8 decimal places
- if |1 - angle| < 0.0001, then
- return True
- return False
Example
Let us see the following implementation to get better understanding −
def solve(l, m, n) : angle = l * l + m * m + n * n angle = round(angle, 8) if abs(1 - angle) < 0.0001: return True return False l = 0.42426 m = 0.56568 n = 0.7071 print (solve(l, m, n))
Input
0.42426, 0.56568, 0.7071
Output
True
- Related Questions & Answers
- Check If It Is a Straight Line in C++
- Check if it is possible to create a polygon with a given angle in Python
- Check if it is possible to create a polygon with given n sidess in Python
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to convert one string into another with given constraints in Python
- Check if it is possible to form string B from A under the given constraint in Python
- Check if it is possible to sort the array after rotating it in Python
- Represent a Given Set of Points by the Best Possible Straight Line in C++
- Check if it is possible to survive on Island in Python
- Check if a triangle of positive area is possible with the given angles in Python
- Check if it is possible to serve customer queue with different notes in Python
- Check if it is possible to reach a number by making jumps of two given length in Python
- Check if it is possible to transform one string to another in Python
- Check if it is possible to rearrange a binary string with alternate 0s and 1s in Python
- Check if is possible to get given sum from a given set of elements in Python
Advertisements