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
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.
- Program to calculate distance between two points
- Program for distance between two points on earth
- Number of Integral Points between Two Points
- Distance between two points travelled by a boat
- Haversine formula to find distance between two points on a sphere
- Check whether it is possible to join two points given on circle such that distance between them is k
- Prime points (Points that split a number into two primes)
- Hammered distance between N points in a 2-D plane
- Distance between end points of Hour and minute hand at given time
- Distance of chord from center when distance between center and another equal length chord is given
- Minimum number of points to be removed to get remaining points on one side of axis
- Steps required to visit M points in order on a circular ring of N points
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Find points at a given distance on a line of given slope
- Find the maximum possible distance from origin using given points
- Find the integer points (x, y) with Manhattan distance atleast N
- Sort an Array of Points by their distance from a reference Point
- Find integral points with minimum distance from given set of integers using BFS
- Calculate speed, distance and time
- Calculate the Square of Euclidean Distance Traveled based on given conditions
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.