Slope to angle?

Started by
7 comments, last by Roof Top Pew Wee 22 years, 1 month ago
I feel bad asking this because it even seems easy to myself, but I can''t seem to come up with the solution. If I have the slope of a line, how do I get the angle for it? --Vic--
Advertisement
Just throwing what I remember from HS math clases out (shouldn't having been sleeping so much). But I do remember the word "SoaCahToh". Basically its all the basic trig functions you need for a right angle triangle.

(Insert image of a right triangle with corners labeled A, B and C)

First think of what angle you want, the angel of A, B or C. Then label the three sides as (h)ypotenuse (the side opposite the right angle), (o)pposite (either the side opposite the point, or if that is the hypotenuse then pick a remaining side) and (a)djacent (the last side).


Now use SoaCahToh to make a formula and solve it for the unknown.

Sin(Angle)=opposite/adjacent
Cos(Angle)=adjacent/hypotenuse
Tan(Angle)=opposite/hypotenuse



Edited by - Michalson on February 16, 2002 4:27:23 PM
I'm an idiot. Forgive me for even posting this. I don't know why I didn't think of it before. I realized I just need the inverse sin and so on. Does Math.h have this function, and if so, what is it called?

--Vic--

Edited by - Roof Top Pew Wee on February 16, 2002 4:31:51 PM
If I remember right, you could always use the inverse of tan. I''m sure math.h has that, instead of inverse sin..

Rather than using adj, hyp and inverse sin, you would use adj, opp and inverse tan.

Oh, and I believe it''s SohCahToa.
JohnPC is right. To find the slope, you probably divide Y by X. That''s what Tan(angle) is. So to find the angle, you just need to do atan(slope).
François DagenaisDagenais.f@videotron.ca
just in case someone does not know this:

Michalson is wrong with his formulas
its acutally "sohcahtoa"

sin(angle) = opposite/hypotenuse
cos(angles)= adjacent/hypotenuse
tan(angle) = opposite/adjacent




There''s a nice function in math.h called atan2. It takes two arguments - first deltaY, then deltaX, and returns the angle. If you just use atan, you need to then add a multiple of 90 degrees that corresponds to the quadrant indicated by the combination of signs. Also note that there are single-precision versions of most of the math functions. Just put an f at the end of each. Example: sinf() instead of sin().
If you have both x and y, don''t do atan(x/y), but atan2(x,y).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I found it a lot easier to memorise the unit circle than the "sohcahtoa" mnemonic.

This topic is closed to new replies.

Advertisement