Given two coordinates (x1, y1, z1) and (x2, y2, z2) in 3D, and m and n, find the co-ordinates that divides the line joining (x1, y1, Z1) and (x2, y2, Z2) in the ratio m : n.
Input : x1 = 2, y1 = -1, Z1 = 4, x2 = 4, y2 = 3, Z2 = 2,
m = 2, n = 3
Output : (2.8, .6, 3.2)
Explanation: co-ordinates (2.8, .6, 3.2)
divides the line in ratio 2 : 3
Given two coordinates A(x1, y1, Z1) and B(x2, y2, Z2) in 3D, and m and n, we have to find the co-ordinates that divides the line joining (x1, y1, Z1) and (x2, y2, Z2) in the ratio m : n.
Let the co-ordinates will be P(x, y, z)
then according to section fORmula in 3 D
x = (m * x2 + n * x1) / (m + n)
y = (m * y2 + n * y1) / (m + n)
z = (m * z2 + n * z1) / (m + n)
Below is the implementation of above approach:
(2.8, 0.6, 3.2)
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.
- Section formula (Point that divides a line in given ratio)
- Recursive program to print formula for GCD of n integers
- Haversine formula to find distance between two points on a sphere
- Find intersection point of lines inside a section
- Check whether count of odd and even factors of a number are equal
- Count of ways to make Array sum even by removing only one element
- Largest square which can be formed using given rectangular blocks
- Find the ratio of LCM to GCD of a given Array
- Maximum absolute difference between distinct elements in an Array
- Count number of Unique Triangles using Operator overloading
- Maximum points of intersections possible among X circles and Y straight lines
- Arrange numbers 1 to N^2 in a Zig-Zag Matrix in ascending order
- What is Indentation, Documentation and Program Maintenance?
- Minimum swaps required to move all vowels occurs after consonants in a given string
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.