janhetjoch
janhetjoch

Reputation: 63

Distance between turtle and a point in Python 2.x

I would like to get the distance between my turtle (which is a Vec2D) and a point ('a' which is also a Vec2D) I have seen ways to get the distance between two points like dist = math.hypot(x2 - x1, y2 - y1) but I want to know the distance without using the full coordinate. Instead, I just want to use 't' and 'a' for my turtle and the point. Does anybody know how to do this?

Upvotes: 1

Views: 3097

Answers (1)

cdlane
cdlane

Reputation: 41872

If I understand your need correctly, you can use t.distance(a). The .distance() method of turtle is flexible in what it will accept as an argument (or arguments) per help(turtle.distance):

distance(x, y)         # two coordinates
distance((x, y))       # a pair (tuple) of coordinates
distance(Vec2d)        # e.g. as returned by position()
distance(other_turtle) # distance to another turtle

Upvotes: 1

Related Questions