|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Geometry & Trig Quiz
Quote:
For example: If x0=0, y0=0, x1=10, y1=-1, and alpha=90 degrees, that formula gives sigma= -5.7 degrees instead of the correct +5.7 degrees. There's a simple alternative to arctan(dx/dy) that gives the correct angle for all values of dx and dy except when they are both zero. Quote:
|
|
#2
|
|||
|
|||
|
Re: Geometry & Trig Quiz
The simple alternative to atan(dy/dx) wouldn't happen to be atan2(dy, dx), would it? I am unsure if the problem permits us to use computer functions that happen to wrap up the conditonal logic nicely.
Edit: I just saw the thread with StangPS and the video. I see you did live up to your comments about disecting the math. Well played. I feel foolish for reinventing the wheel now. Last edited by Aaron.Graeve : 27-10-2013 at 02:24. |
|
#3
|
||||
|
||||
|
Re: Geometry & Trig Quiz
Quote:
atan's range is limited to -90 < atan < +90. So if the problem involves an angle like 95.7 degrees (as in the previously posted example), atan cannot return that value. atan2's range is -180 <= atan2 <= +180 and it handles the quadrantal angles without crashing. Also, in many implementations (Octave is an example) atan2 handles the arguments (0,0) and returns 0. You can wrap conditional logic around atan in your own code to produce your own version of atan2, but it's better to use the library version if it's available. Pages 152 thru 158 of P J Plauger's classic 1992 book The Standard C Library shows a reference implementation of atan and atan2. I don't think you re-invented the wheel. Your diagram and accompanying explanation stated the simplifying assumptions explicitly, used a consistent reference coordinate system, and were very clear and easy to understand. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|