I never used python but now I need a code to do this calculation:

I'm doing this:

math.atan(math.fabs( !Y2! - !Y1!)/math.fabs( !X2! - !X1!) )*(180/math.pi)

Could you do something like:

Pre-Logic Script code:

def mathFunction(y1, y2, x1, x2):
  return math.Atan(math.fabs(y2-y1) / math.fabs(x2-x1)) * (180/math.pi)

Field = (on the bottom)...populate with your fields for y1,y2,x1,x2

mathFunction(!FIELDY1!, !FIELDY2!,!FIELDX1!,!FIELDX2!)

See Python doc on the math module.

Here is a screenshot


Are you looking for atan2 ? It's precisely meant to deal with this signs mess.


  • I'm looking for atan – AndM Apr 16 '15 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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