|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Geometry & Trig Quiz
Quote:
Actually, since the bot as described does not rotate, any point on the bot could have been used (as long as it was the same point for both the initial and final coords). Quote:
The formula you gave gives the "correct" angle if y1>y0, but gives the "reverse" angle (180 degrees off) if y1<y0. If y1=y0, it crashes. For example: 1) if x0=0, y0=0, x1=10, y1=-1, and alpha=90 degrees, the formula gives sigma= -174.3 degrees instead of +5.7 degrees. 2) if x0=0, y0=0, x1=10, y1=0, and alpha=60 degrees, the formula crashes instead of sigma=30 degrees. There's a simple way fix the formula that does not involve any conditional logic in your code. Quote:
|
|
#2
|
|||
|
|||
|
Re: Geometry & Trig Quiz
From my reasoning, the code only crashes due to a division by zero in the arctangent function. This could be fixed by using arcsin ((x1-x0)/sqrt ((x1-x0)^2+(y1-y0)^2)). This crashes if the inital and final positions are the same, but the problem is meaningless if you are already at yor final position.
Regarding the smallest Delta, either a conditional check on the absolute value of Delta being larger than 180 degrees or running the delta through arcsin(sin(Delta)) could do the trick. I know the second suggestion is implemetation dependent and not the ideal method but it is a method that I think will work in most cases. Last edited by Aaron.Graeve : 26-10-2013 at 19:40. |
|
#3
|
||||
|
||||
|
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:
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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 |
|
|