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)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 16, 2015 at 11:57
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

answered Apr 16, 2015 at 12:13
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

answered Apr 16, 2015 at 15:49
1
  • I'm looking for atan Commented Apr 16, 2015 at 16:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.