Given two lines L1 and L2, each passing through a point whose position vector are given as (X, Y, Z) and parallel to line whose direction ratios are given as (a, b, c), the task is to check whether line L1 and L2 are coplanar or not.
Coplanar: If two lines are in a same plane then lines can be called as coplanar.
L1: (x1, y1, z1) = (-3, 1, 5) and (a1, b1, c1) = (-3, 1, 5)
L2: (x1, y1, z1) = (-1, 2, 5) and (a1, b1, c1) = (-1, 2, 5)
Output: Lines are Coplanar
L1: (x1, y1, z1) = (1, 2, 3) and (a1, b1, c1) = (2, 4, 6)
L2: (x1, y1, z1) = (-1, -2, -3) and (a1, b1, c1) = (3, 4, 5)
Output: Lines are Non-Coplanar
In above equation of line a vector is the point in 3D plane from which given line is passing through called as position vector a and b vector is the vector line in 3D plane to which our given line is parallel. So it can be said that the line(1) passes through the point, say A, with position vector a1 and is parallel to vector b1 and the line(2) passes through the point, say B with position vector a2 and is parallel to vector b2. Therefore:
Here cross product of vectors b1 and b2 will give the another vector line which will be perpendicular to both b1 and b2 vector lines. and AB is the line vector joining the position vectors a1 and a2 of two given lines. Now, check whether two lines are coplanar or not by determining above dot product is zero or not.
Therefore, for both type of forms needs a position vectors a1 and a2 in input as (x1, y1, z1) and (x2, y2, z2) respectively and direction ratios of vectors b1 and b2 as (a1, b1, c1) and (a2, b2, c2) respectively.
Follow the steps below to solve the problem:
- Initialize a 3 X 3 matrix to store the elements of the Determinant shown above.
- Calculate the cross product of b2 and b1 and dot product of (a2 – a1).
- If the value of the Determinant is 0, the lines are coplanar. Otherwise, they are non-coplanar.
Below is the implementation of the above approach:
Lines are coplanar
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether two straight lines are orthogonal or not
- Find whether only two parallel lines contain all coordinates points or not
- Distance between two parallel lines
- Check if given two straight lines are identical or not
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Check if three straight lines are concurrent or not
- Maximum distinct lines passing through a single point
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Number of triangles formed from a set of points on three lines
- Total number of triangles formed when there are H horizontal and V vertical lines
- Maximum number of region in which N non-parallel lines can divide a plane
- Count number of pairs of lines intersecting at a Point
- Maximum points of intersections possible among X circles and Y straight lines
- Python - Find the maximum number of triangles with given points on three lines
- Number of pairs of lines having integer intersection points
- Find the maximum value of Y for a given X from given set of lines
- Number of lines from given N points not parallel to X or Y axis
- Angle between a Pair of Lines in 3D
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Number of cycles in a Polygon with lines from Centroid to Vertices
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : offbeat