2005-01-09 01:16:16 +00:00
|
|
|
# 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
|
|
|
|
|
|
2009-05-20 19:34:01 +01:00
|
|
|
from physics import Vector3D
|
2005-01-09 01:16:16 +00:00
|
|
|
|
|
|
|
|
compass_points=[(Vector3D(1,0,0), "east"),
|
2018-01-18 22:27:56 +01:00
|
|
|
(Vector3D(0, 0, -1), "north"),
|
|
|
|
|
(Vector3D(0, 0, 1), "south"),
|
|
|
|
|
(Vector3D(-1, 0, 0), "west"),
|
|
|
|
|
(Vector3D(0.707, 0, -0.707), "north east"),
|
|
|
|
|
(Vector3D(-0.707, 0, -0.707), "north west"),
|
|
|
|
|
(Vector3D(0.707, 0, 0.707), "south east"),
|
|
|
|
|
(Vector3D(-0.707, 0, 0.707), "south west")]
|
2005-01-09 01:16:16 +00:00
|
|
|
|
|
|
|
|
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
|