1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Tough Angle problem

  1. Nov 25, 2007 #1
    This is a tough angle problem (For me),

    In the diagram below, I have two cases, A and B. In each case, when I sequentially compare the black, blue, and then green lines to the previous line, in each case you end up with the following angles: ~30 and ~30. Yet clearly the spatial relationships of the lines in cases A and B are different!

    So how could I measure lines sequentially, so I can build up a relationship of 360 degree angles between the lines?

    refering to the image, case A would rightfully measure ~30 degrees then ~330 degrees. case B would measure ~30 and ~30 again.

    Hope that made sense.


    Attached Files:

    Last edited: Nov 26, 2007
  2. jcsd
  3. Nov 26, 2007 #2


    User Avatar
    Science Advisor

    Have you ever thought about using +ive and negative numbers to represent your angles. For example +ive for a counter-clockwise angle and -ive for a clock-wise angle?
  4. Nov 26, 2007 #3
    It might be useful to measure the angle of each next segment with respect of the prolongation of the previous; in the attached image, the green line would be measure against the dotted line. An angle of 0 would represent the next segment continuing in exactly the same direction; a positive angle would be a left (counter-clockwise) turn, negative angles for right (clockwise). This is useful if you want to accumulate the total change of orientation as the line progresses: you would only need to sum the angles.

    Attached Files:

  5. Nov 26, 2007 #4
    Uart and Dodo, both your insights are correct, I need to compare which "side" the new line is on relative to the old one. However, the current problem is I have no way of deciding which side is the one which will measure greater than 180 degrees, and which one less, based on what the previous angle measurement was. I just don't know how to mathematically relate a side of a line to either the >180 or <180 degrees.

    Thanks again :)
  6. Nov 26, 2007 #5
    Exactly what data do you have? The coordinates of the endpoints of the segments, for example?
  7. Nov 26, 2007 #6
    Yep Dodo, a sequential list of all points, including knowing what the 'first' and 'last' points are. Each point is both the beginning and end of a 'line' (unless its the first or last point of course)
    Last edited: Nov 26, 2007
  8. Nov 26, 2007 #7
    Then you have everything you need.

    Most calculators (or programming languages in a computer) will have an inverse tangent, tan^-1, or arctan, function. Let P and Q be the endpoints of some segment; and let dx = Qx-Px, and dy = Qy-Py. Then, in theory, arctan(dy/dx) gives you the angle between that segment and the horizontal, possibly in the range -90...+90.

    In practice, you would use the signs of dx and dy to complete your choice of angle. In practice, you would avoid vertical segments (where dx=0), to avoid a zero division. You can accomplish both things by using the following trick: choose the maximum of |dx| and |dy| (where |dx| means the absolute value of dx, the magnitude of dx without considering the sign), and calculate the arctan(dy/dx) if |dx| is bigger, or arctan(dx/dy) if |dy| is bigger. Then transform the angle you get into the "real" one, according to the choice you made, and according to the signs of dx and dy. This "real" angle is usually chosen positive from 0 to 180 (the region above the X axis), or negative from 0 to -180.

    There are 8 possible cases you have to consider (dx positive or negative, dy positive or negative, |dx| bigger or smaller than |dy|) which correspond to the 8 octants of the whole circle (the 8 pieces of the circle in 45-degrees steps). Give some thought to what happens on each of the 8 cases, and come back with more question at whichever point you get stuck, if at all.

    Here is an example: for points P=(105, 106) and Q=(108, 102), you have dx = 3, dy = -4. Now, since the absolute value of -4 (which is 4) is greater than the absolute value of 3 (which is the same 3), we choose to calculate the angle arctan(dx/dy) = arctan(3/-4) = -36.87 degrees (aprox.). Since your choice was to invert dx and dy (and divide by dy, when the "theoretical" formula divided by dx instead), you are really calculating, loosely speaking, the angle with respect to the vertical (you have to imagine interchanging the x and y axis). I have attached a picture; there you can see the -36.87 angle, and the final, "real" angle which in this case is -90 + 36.87 = -53.13 degrees (I hope the picture illustrates why). Minus 53.13, because it is under the X axis.

    Of course, once you have a (signed) angle for each individual segment, a simple subtraction will give you the relative, signed angle differences.

    Attached Files:

    Last edited: Nov 26, 2007
  9. Nov 26, 2007 #8
    Alright, I think that sounds like it will work. However, being a self-taught computer science and non-math guy, I can't conceptually understand everything you said :biggrin: I understand enough to implement it in software (C++) however, except for this one aspect:

    I hope I can pick your brain to understand this last bit. When you say the "according to the choice you made", are you refering to choosing to divide by dx or dy, this is automatic isn't it, based on just which one is bigger (in absolute terms)? If not, how do I make this choice? Secondly you also said "and according to the signs of dx and dy"; how do I do this deciding based on the signs of dx or dy, in order to further decide the "real" angle, in terms of +/-180 degrees?

    In any case, I greatly appreciate all help rendered up to this point :)
  10. Nov 27, 2007 #9
    Well, I know you need help, but I really didn't want to do all the work myself. I propose the following experiment:

    Write a C program that accepts two floating-point values, a, b, and calculates the value of 180 * atan(a/b) / M_PI, where M_PI is the 'pi' constant (3.14159...) that you get for free when you #include <math.h>. The purpose of multiplying by 180 and dividing by pi is, of course, to convert the value returned by atan, from radians to degrees.

    Now, the red dots in the attached picture are possible values of dx, dy. Try running your program, choosing (by hand) a=dx and b=dy when dy is bigger in absolute value, and a=dy, b=dx on the contrary. Get sure to try dx, dy values on each of the 8 octants, which I have drawn for your ease of use. You can start with the big red dot in the picture, which corresponds to the example at the bottom of my previous post.

    In each case, you'll notice that you get angles with respect to the horizontal (green) X axis when dividing by dx, and angles with respect to the vertical (red) Y axis when dividing by dy. And your final goal is to pick a formula (typically, one of 90 + angle, -90 - angle, 180 + angle, of just the angle) that converts, for each of the 8 cases, from the output of the program to the angle you want (I suggest You Want an angle with respect to the right half of the X axis, as in the picture of the previous post).

    Please try the above, and let me know if/when you have further problems.

    Attached Files:

    • axes.gif
      File size:
      834 bytes
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook