#!/usr/bin/env python # -*- coding: utf-8 -*- import math #------------------------------------------------------------------------------- # toStandardAngle(). # Returns the given angle in the 0-359 range. # # Parameters: # aAngle: Angle to check. # # Returns: The same angle in the 0-359 range. #------------------------------------------------------------------------------- def toStandardAngle(aAngle): aAngle = aAngle % 360; if (aAngle < 0): aAngle = aAngle + 360 return(aAngle) #------------------------------------------------------------------------------- # radToDeg(). # Convert the angle given in radians to degrees. # # Parameters: # aAngle: Angle in radians to be converted. # # Returns: The angle in degrees. #------------------------------------------------------------------------------- def radToDeg(aAngle): return aAngle * 180 / math.pi #return aAngle * 180 / 3.1415927 #------------------------------------------------------------------------------- # degToRad(). # Convert the angle given in degrees to radians. # # Parameters: # aAngle: Angle in degrees to be converted. # # Returns: The angle in radians. #------------------------------------------------------------------------------- def degToRad(aAngle): return aAngle * math.pi / 180 #return aAngle * 3.1415927 / 180 def dist(ax1, ay1, ax2, ay2): return math.sqrt((ax2-ax1)**2 + (ay2-ay1)**2) # determine if a point is inside a given polygon or not # Polygon is a list of (x,y) pairs. # http://www.ariel.com.au/a/python-point-int-poly.html # http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ def pointInsidePolygon(x, y, poly): n = len(poly) inside =False p1x,p1y = poly[0] for i in range(n+1): p2x,p2y = poly[i % n] if y > min(p1y,p2y): if y <= max(p1y,p2y): if x <= max(p1x,p2x): if p1y != p2y: xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x if p1x == p2x or x <= xinters: inside = not inside p1x,p1y = p2x,p2y return inside def pointInsideRectangle(x, y, rect): x1 = rect[0][0] y1 = rect[0][1] x2 = rect[1][0] y2 = rect[1][1] if (x > x1) and (x < x2): if (y > y1) and (y < y2): return True return False