Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,877 questions

51,801 answers

573 users

How to calculate the Euclidean distance between two points in TypeScript

1 Answer

0 votes
// The Euclidean distance is a measure of the straight-line distance 
// between two points in a 2D or 3D space

function CalculateEuclideanDistance(x1: number, y1: number, x2: number, y2: number): number {
  // Calculate Euclidean distance between two 2D points
  return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

const x1: number = 3.0;
const y1: number = 4.0;
const x2: number = 5.0;
const y2: number = 9.0;

const distance: number = CalculateEuclideanDistance(x1, y1, x2, y2);
console.log(`Euclidean Distance: ${distance.toFixed(5)}`);




/*
run:

"Euclidean Distance: 5.38516" 

*/


 



answered Oct 13, 2025 by avibootz
edited Oct 13, 2025 by avibootz
...