ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 19 Dec 2015 12:59:27 -0600Best way to represent a pointhttp://ask.sagemath.org/question/31699/best-way-to-represent-a-point/ Hello,
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 advanceSat, 19 Dec 2015 08:50:36 -0600http://ask.sagemath.org/question/31699/best-way-to-represent-a-point/Answer by vdelecroix for <p>Hello,</p>
<p>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</p>
http://ask.sagemath.org/question/31699/best-way-to-represent-a-point/?answer=31701#post-id-31701You should use vectors
sage: p = vector((3,4))
sage: q = vector((0,-1))
sage: 2*p
(6, 8)
sage: p + q
(3, 3)Sat, 19 Dec 2015 12:59:27 -0600http://ask.sagemath.org/question/31699/best-way-to-represent-a-point/?answer=31701#post-id-31701