I'm making a Line class in python and the attributes we need to put in are the first point, end point, latitude, departure, distance, and azimuth (from the South). The points consists of eastings and northings. I understand that I need the azimuth first to calculate the latitude and departure. My question is how do I obtain the correct azimuth from the south with the two points?

I know the formula arctan((x2-x1)/(y2-y1)) must be used but that will not yield the correct azimuth from the south. How do I make the code without making another method?

Restriction: We can only use the math module. I have this code so far.

class Line:
    def __init__(self,first,end):
        self.first = first #Type:Point (x1,y1)
        self.end = end #Type:Point (x2,y2)
        self.dist_x = self.end.x - self.first.x
        self.dist_y = self.end.y - self.first.y
        self.distance = math.sqrt((self.dist_x)**2 + (self.dist_y)**2)
        #self.azimuth = math.atan2((self.dist.x)/(self.dist.y))
        #self.latitude = 
        #self.departure =

1 Answer 1


I'm not quite sure I understand what you are asking, but:

Notice that math.atan2 takes two arguments, deltay and deltax, in that order. It will give you the angle, in radians, anticlockwise from the three-o-clock position. I'm not familiar with how azimuths from the south are defined, but to get a clockwise-from-north azimuth, I'd do

az = (90 - math.degrees(math.atan2(dy, dx)) % 360

math.degrees(...) converts to degrees, 90 - ... takes care of the reference direction and clockwise/anticlockwise flip, and finally ... % 360 gets rid of any negative values. For clockwise-from-south, you could do 270 - ... instead.

WARNING: you can use the % operator like this in Python, but it would not work in e.g. C (or, I think, Java) because different languages handle negative values differently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.