Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Wednesday, May 8, 2013

Euclidean Distance


Problem: Compute the Euclidean distance between two 2-dimensional points.

Solution in Python:

import math

def compute_euclidean_distance(x1, y1, x2, y2):
    """
    Author: Mayur P Srivastava
    """

    dx = x2 - x1
    dy = y2 - y1
    return math.sqrt(dx*dx + dy*dy)


Concepts Learned: Numbers.


No comments:

Post a Comment