Ask Your Question

Best way to represent a point

asked 2015-12-19 08:50:36 -0500

Neabfi gravatar image


I have a point p1(x1, y1) and a point p2(x2, y2). For example I want p1 = 2 * p2 For the moment I store the points in lists so I have to do like: p1[0] = 2 * p2[0] p1[1] = 2 * p2[1] It's very ugly. What's the best way to do that ? Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-12-19 12:59:27 -0500

vdelecroix gravatar image

You should use vectors

sage: p = vector((3,4))
sage: q = vector((0,-1))
sage: 2*p
(6, 8)
sage: p + q
(3, 3)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-12-19 08:50:36 -0500

Seen: 86 times

Last updated: Dec 19 '15