2

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)
0

2 Answers 2

4

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

0
1

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

https://docs.python.org/2/library/math.html#math.atan2

1
  • I'm looking for atan
    – AndM
    Commented Apr 16, 2015 at 16:25

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.