Given two coordinates (x1, y1, z1) and (x2, y2, z2) in 3 dimension. The task is to find the distance between them.
Input: x1, y1, z1 = (2, -5, 7) x2, y2, z1 = (3, 4, 5) Output: 9.2736184955 Input: x1, y1, z1 = (0, 0, 0) x2, y2, z1 = (1, 1, 1) Output: 1.73205080757
Approach: The formula for distance between two points in 3 dimension i.e (x1, y1, z1) and (x2, y2, z2) has been derived from Pythagorean theorem which is:
Below is the implementation of above formulae:
Distance is 9.2736184955
- Program to calculate distance between two points
- Program for distance between two points on earth
- Hammered distance between N points in a 2-D plane
- Distance between two points travelled by a boat
- Calculate speed, distance and time
- Check whether it is possible to join two points given on circle such that distance between them is k
- Find the maximum possible distance from origin using given points
- Find points at a given distance on a line of given slope
- Haversine formula to find distance between two points on a sphere
- C program to calculate the value of nPr
- Program to calculate age
- Program to calculate value of nCr
- Program to calculate the value of sin(x) and cos(x) using Expansion
- Program to Calculate e^x by Recursion
- Write a program to calculate pow(x,n)
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.