# - - - L i n e . p o i n t B e a r i n g @staticmethod def pointBearing(p, bears): '''Line through p at angle (bears). '''
To find the equation of a line through a given point with a given bearing, in most cases we use the point-slope form of the equation of a line:
However, note that when the angle is a multiple of
90°, finding the tangent is not going to work. In
these cases, the line is vertical and has the equation
x1 is the abscissa of point
First we standardize the angle to the interval [0,π). Then we can test to see if it is vertical.
#-- 1 -- # [ angle := angle normalized to [0,180) degrees # px := abscissa of p # py := ordinate of p ] angle = bears % RAD_180 px, py = p.xy() #-- 2 -- # [ if angle == RAD_90 -> # return a Line with a=1.0, b=0.0, and c=-p.x() # else -> # m := tan(angle) ] if angle == RAD_90: return Line(1.0, 0.0, -px) else: m = num.tan(angle)
Here's the general case.
#-- 3 -- # [ return a Line with a=m, b=-1.0, and c=(-m*px + py) ] return Line(m, -1.0, py - m*px)