Given two line segments AB and CD having A(x1, y1), B(x2, y2), C(x3, y3) and D(x4, y4). The task is to check whether these two lines are orthogonal or not. Two lines are called orthogonal if they are perpendicular at the point of intersection.
Input: x1 = 0, y1 = 3, x2 = 0, y2 = -5 x3 = 2, y3 = 0, x4 = -1, y4 = 0 Output: Yes Input: x1 = 0, y1 = 4, x2 = 0, y2 = -9 x3 = 2, y3 = 0, x4 = -1, y4 = 0 Output: Yes
Approach: If the slopes of the two lines are m1 and m2 then for them to be orthogonal we need to check if:
- Both lines have infinite slope then answer is no.
- One line has infinite slope and if other line has 0 slope then answer is yes otherwise no.
- Both lines have finite slope and their product is -1 then the answer is yes.
Below is the implementation of the above approach:
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 if given two straight lines are identical or not
- Check whether a given matrix is orthogonal or not
- Check if three straight lines are concurrent or not
- Check if two given Circles are Orthogonal or not
- Maximum points of intersections possible among X circles and Y straight lines
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Count straight lines intersecting at a given point
- Find whether only two parallel lines contain all coordinates points or not
- Check whether a straight line can be formed using N co-ordinate points
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Check whether two convex regular polygon have same center or not
- Number of lines from given N points not parallel to X or Y axis
- Represent a given set of points by the best possible straight line
- Length of the normal from origin on a straight line whose intercepts are given
- Area of triangle formed by the axes of co-ordinates and a given straight line
- Straight-line Number
- Puzzle | Place numbers 1 to 9 in a Circle such that sum of every triplet in straight line is 15
- Program for Point of Intersection of Two Lines
- Distance between two parallel lines
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.