• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
November 23, 2022 |2.1K Views

Javascript program to find the Euclidean distance between two points

  Share  1 Like
Description
Discussion

In this video, we will write a JavaScript program to find the Euclidean distance between two points. 
So basically here, in given two coordinates( x1, y1) and( x2, y2) of a two-dimensional graph and we need to find the distance between them. 

In mathematics, the Euclidean distance between two points in Euclidean space is the length of a line partition between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, hence sometimes being called the Pythagorean distance. 

Examples 
Input: 
x1, y1 = ( 3, 4) 
x2, y2 = ( 5, 3) 
Output = 2.236067977 

Input: 
x1, y1 = ( 3, 4) 
x2, y2 = ( 8, 9) 
Output = 7.0710678118654 

Time Complexity O( log n) 
Auxiliary Space O(1) 

Algorithm 
Step1 First, take the input of coordinates of the two points. 
Step 2 Apply the formula for calculating Euclidean distance. That's 
Euclidean Distance = sqrt(( x2- x1) 2( y2- y1) 2) 
Step 3 Print the result