File: compass.py

package info (click to toggle)
cyphesis-cpp 0.5.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,084 kB
  • ctags: 3,627
  • sloc: cpp: 30,418; python: 4,812; xml: 4,674; sh: 4,118; makefile: 902; ansic: 617
file content (25 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (2)
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
# This file may be redistributed and modified only under the terms of
# the GNU General Public License (See COPYING for details).
# Copyright (C) 2005 Alistair Riddoch

from Vector3D import Vector3D

compass_points=[(Vector3D(1,0,0), "east"),
                (Vector3D(0,1,0), "north"),
                (Vector3D(0,-1,0), "south"),
                (Vector3D(-1,0,0), "west"),
                (Vector3D(0.707,0.707,0), "north east"),
                (Vector3D(-0.707,0.707,0), "north west"),
                (Vector3D(0.707,-0.707,0), "south east"),
                (Vector3D(-0.707,-0.707,0), "south west")]

def vector_to_compass(direction):
    dot=-1
    ret="unknown"
    dir=direction.unit_vector()
    for point in compass_points:
        new_dot = dir.dot(point[0])
        if new_dot > dot:
            dot = new_dot
            ret = point[1]
    return ret