GeoffreyTaucer
GeoffreyTaucer

Reputation: 11

Converting sympy point object to tuple of coordinates

I'm working on a project in which I'm using sympy to (among other things) find the midpoint between two points in a 2D image. Since midpoint gives me a sympy point object, how can I convert this to a simple tuple of the coordinates?

EDIT: here's what I have:

vertex = Segment(hipL, hipR).midpoint
vertex = tuple(vertex)

Here's the error I'm getting: TypeError: 'method' object is not iterable

EDIT 2: changed to this:

vertex = Point(hipL).midpoint(hipR)
vertex = tuple(vertex)

Seems to be working.

Upvotes: 0

Views: 1860

Answers (1)

user6655984
user6655984

Reputation:

Use tuple:

from sympy import Point, Segment
a = Point(2, 3)
b = Point(3, 7)
print(tuple(a.midpoint(b)))
print(tuple(Segment(a, b).midpoint))

prints the tuple (5/2, 5) twice in SymPy 1.3. If it does not work for you, update SymPy.

Upvotes: 1

Related Questions