Given four co-ordinates A, B, C and D where towers need to be constructed, the task is to check if the tower of sight issue occurs or not.
Tower of sight issue occurs if the towers at A or C lies in the line joining B and D or vice versa.
Input: A = (0, 0), B = (0, -2), C = (2, 0), D = (0, 2)
Tower A lies in the line joining B and D.
Input: A = (0, 0), B = (0, -2), C = (2, 0), D = (0, -5)
No intersection occurs.
- If A and C are parallel to the X-axis, check if B or D has y coordinate equal to that of A and C and x coordinate in between that of A and C.
- If A and C are parallel to the Y-axis, check if B or D has x coordinate equal to that of A and C and y coordinate in between that of A and C.
- Otherwise, check if B or D satisfies the line equation of A and C.
- Similarly follow the above three steps to check if A or C lies in between B or D.
Below code is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sort elements of the array that occurs in between multiples of K
- Count of Numbers in a Range where digit d occurs exactly K times
- Check whether a given number is even or odd
- Check whether N is a Factorion or not
- Check whether the exchange is possible or not
- Check whether it is possible to convert A into B
- Check n^2 - m^2 is prime or not
- Check if given coins can be used to pay a value of S
- Check divisibility by 7
- Check if the sum of digits of N is palindrome
- Check whether a given number is Polydivisible or Not
- Check whether a number is semiprime or not
- Check whether the given integers a, b, c and d are in proportion
- Check if two Integer are anagrams of each other
- Check if two given Circles are Orthogonal or not
- Check if it is possible to move from (0, 0) to (X, Y) in exactly K steps
- Check whether Bishop can take down Pawn or not
- Check whether XOR of all numbers in a given range is even or odd
- Check whether a given matrix is orthogonal or not
- Check whether a number is Emirpimes or not
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.