Next / Previous / Contents / Shipman's homepage

7.5. Pt.dist(): Distance between two points

Maybe this function should overload subtraction (.__sub__())? In any case, the good old Pythagorean theorem is all the math we need.

homcoord.py
# - - -   P t . d i s t

    def dist(self, other):
        '''Return the distance between self and other.
        '''
        dx = self.x() - other.x()
        dy = self.y() - other.y()
        return num.sqrt ( dx*dx + dy*dy )