Calculate 2D Euclidean Distance

  • Share this:

Code introduction


Calculate the Euclidean distance between two points in a 2D space.


Technology Stack : math library (mathematical functions), re library (regular expressions), os library (operating system), sys library (system), time library (time)

Code Type : Calculation function

Code Difficulty : Intermediate


                
                    
import math
import os
import re
import sys
import time

def calculate_euclidean_distance(point1, point2):
    """
    Calculate the Euclidean distance between two points in a 2D space.
    """
    return math.sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2)