-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVect.py
52 lines (41 loc) · 1.61 KB
/
Vect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
###############################################################################
# Vect.py
#
# Some simple 2D vector operations.
#
# -----------------------------------------------------------------------------
# gpsmap - A GPSD simulator based on map positions
# (C) 2014 Gerardo García Peña <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
###############################################################################
import math
def vect(vx, vy):
return [ float(vx), float(vy) ]
def vsub(va, vb):
return [ vb[0] - va[0], vb[1] - va[1] ]
def vsum(va, vb):
return [ vb[0] + va[0], vb[1] + va[1] ]
def vmod(v):
return math.sqrt(v[0]*v[0] + v[1]*v[1])
def vangle(a, b):
return math.acos((a[0]*b[0] + a[1]*b[1]) / (vmod(a) * vmod(b)))
def vangle2(a, b):
return math.atan2(b[1], b[0]) - math.atan2(a[1], a[0])
def vstr(v):
return "(%f, %f)" % (v[0], v[1])