- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Given with the 3-D plane and hence three coordinates and the task is to find the distance between the given points and display the result.

In a three dimension plane there are three axis that are x-axis with its coordinates as (x1, y1, z1), y-axis with its coordinates as (x2, y2, z2) and z-axis with its coordinates as (x3, y3, z). To calculate the distance between them there is a direct formula which is given below

$$\sqrt{\lgroup x2-x1\rgroup^{2}+\lgroup y2-y1\rgroup^{2}+\lgroup z2-z1\rgroup^{2}}$$

**Given below is the diagram representing three different axis and their coordinates**

**Approach used below is as follows** −

- Input the coordinates as (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3)
- Apply the formula to compute the difference between these points
- Print the distance

Start Step 1-> declare function to calculate distance between three point void three_dis(float x1, float y1, float z1, float x2, float y2, float z2) set float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2) * 1.0) print dis step 2-> In main() Set float x1 = 4 Set float y1 = 9 Set float z1 = -3 Set float x2 = 5 Set float y2 = 10 Set float z2 = 9 Call three_dis(x1, y1, z1, x2, y2, z2) Stop

#include <stdio.h> #include<math.h> //function to find distance bewteen 3 point void three_dis(float x1, float y1, float z1, float x2, float y2, float z2) { float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2) * 1.0); printf("Distance between 3 points are : %f", dis); return; } int main() { float x1 = 4; float y1 = 9; float z1 = -3; float x2 = 5; float y2 = 10; float z2 = 9; three_dis(x1, y1, z1, x2, y2, z2); return 0; }

IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT

Distance between 3 points are : 12.083046

- Related Questions & Answers
- C program to calculate distance between two points
- Program to Find the Shortest Distance Between Two Points in C++
- Program to check if three points are collinear in C++
- Java Program to calculate distance light travels
- Three Different ways to calculate factorial in C#
- Calculate distance and duration between two places using google distance matrix API in Python?
- Angle between two Planes in 3D in C Program?
- How to calculate power of three using C#?
- How to calculate mahalanobis distance in R?
- Finding distance between two points in a 2-D plane using JavaScript
- C++ Program to Calculate Difference Between Two Time Period
- Number of Integral Points between Two Points in C++
- Creating 3D Globe using React-three-fiber
- Creating 3D Text using React-three-fiber
- Program to find the minimum edit distance between two strings in C++

Advertisements