Math help needed - Warning complex equation!!....read only if brain is in stable conditon

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Thu Feb 6 09:18:41 EST 2003


jranchordas at hotmail.com (Jay) writes:
> right, now that I got your attention, I need help on the following
> piece of python code:
> 
> distance = 1.15 * (180 * (acos((sin(pi * lat1 / 180) * sin(pi * lat2 /
> 180)) + (cos(pi * lat1 / 180) * cos(pi * lat2 / 180) * cos(pi * (lon2
> – lon1) / 180))) / pi) * 60)
> 
> when trying to compile I get the error "SyntaxError: invalid syntax".

Try putting a backslash at the end of the line when you want it to be
continued on the next line.  Python doesn't always figure out what you
want.

Also, why not convert the angles to radians separately:

    def r(deg): return deg*180./pi
    lat1r, lon1r, lat2r, lon2r = r(lat1), r(lon1), r(lat2), r(lon2)
    distance = ...
   
That cleans up your distance formula considerably by removing the
conversions.




More information about the Python-list mailing list