views:

104

answers:

6

I need to obtain the supplement of an angle.

Exactly what I need to do is to implement some kind of code that mirror the angle, let's say, I have 45 degrees -> 135, another example: 80 ->100, 0 degrees -> 180, and so on.

Solved: I implemented this just a moment ago, and it worked perfectly, I use 180 - angle if angle < 180, and 360 - angle if angle >= 180.

+2  A: 

I think you're after 180 - yourAngle.

Your examples:

  • 45 degrees: 180 - 45 = 135
  • 80 degrees: 180 - 80 = 100
  • 0 degrees: 180 - 0 = 180
aioobe
Yes, that worked ok but, what if my angle is 225?, if I do that then I'll get 180 - 225 = -45, and I should get 135.Maybe I should use 360 - angle if my angle is > 180.
Artemix
@Artemix: So normalize the angle between 0 and 180 (by adding/subtraction 180 until you are between [0, 180) )
BlueRaja - Danny Pflughoeft
Yes, I know that, but I'm asking if am'I correct if I do 360 - myAngle when myAngle > 180.
Artemix
@Artemix: you are doing your arithmetic mod 180, so adding 360 is the same as adding 180. That is, `(360-angle) mod 180 = (180-angle) mod 180 = (-angle) mod 180`. Here I am using mod in the mathematical sense, where `(-1 mod 180) = 179`, not +1. Thus, even multiplying your angle by -1 and adding/subtracting 180 until you are between [0, 180) will give you a correct answer.
BlueRaja - Danny Pflughoeft
+1  A: 
reflected_angle = 180 - ray_angle
AraK
+4  A: 

Subtraction will probably work (if the universe is Euclidean).

http://en.wikipedia.org/wiki/Supplementary_angles

msw
+1  A: 

The simplest answer, based on what you appear to be asking about is

angle2 = 180 - angle1
murgatroid99
A: 

If you view your "angle" as a 2D vector in the plane, you simply change the sign of the component normal to the "mirror" plane.

So, for example, a 45 degree angle (1, 1) "mirrored" in the yz-plane becomes (-1, 1).

duffymo
Yes, that was EXACTLY what I thought in the first place, but when I tryied to do that on the code, I found some problems. Thing is, I didnt find a way to "reconstruct" the angle using the new components.
Artemix
Post your code, because this is exactly correct. The problem was in your code.
duffymo
If you've accepted the answer, why not vote it up as well?
duffymo
A: 

Thx guys, I implemented this just a moment ago, and it worked perfectly, I use 180 - angle if angle < 180, and 360 - angle if angle >= 180.

All answers were ok.

Artemix
Make sure you accept one of them!
Dan Puzey
Edit your question and add this info up there, a lot of people won't find it hidden down here in an answer.
bta
@Dan I actually clicked all as "ok"... weird.@bta ok
Artemix