Ask Your Question
1

Best way to represent a point

asked 9 years ago

Neabfi gravatar image

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 advance

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 9 years ago

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)
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 9 years ago

Seen: 300 times

Last updated: Dec 19 '15