Reputation: 31
I'm trying to determine the length of the red line in the example below for a iOS app. Given a height in blue (eg: 10cm), and an angle of tilt on the blue line (eg: 60-degrees), I need to know the length of the red line.
The top of the blue line will always be 90-degrees, which points down and will determine the end of the red line.
I've asked this on the math section and I received this answer:
I just have no idea how to convert this formula to objective-c, so that I can determine b, which is the length of the red line.
Any help would be appreciated!
Upvotes: 0
Views: 188
Reputation: 1102
Blue=sin(90-degree)*red => blue=sin(30)*red=> blue=0.5*red=> red=2*blue=> red=20
Green^2=red^2-blue^2=> green=10 sqrt(3)
Or green=cos(90-degree)*red= 10 sqrt(3)
Upvotes: 0
Reputation: 438467
When dealing with a right triangle, you can use the cosine function, namely that the cosine of the angle is equal to the length of the adjacent side (i.e., the blue length) divided by the length of the hypotenuse (i.e., the red length). Just remember that the trigonometric functions use radians, not degrees, so make sure to convert your angle to radians before using any of the trigonometric functions.
So, solving for the red length, that yields:
CGFloat angleInDegrees = 60.0;
CGFloat blueLength = 10.0;
CGFloat angleInRadians = angleInDegrees * M_PI / 180.0;
CGFloat redLength = blueLength / cosf(angleInRadians);
Upvotes: 1
Reputation: 5594
lets simplify based on your facts
B = 90 degrees sin 90 = 1
c = known length A = known angle
geometry fact A+B+C = 180 so C = 180 - A - B C = 90-A
start with formula and simplify then: b/sinB = c/SinC
b/1 = b
finally... b = c (known) / sin (90-A (known))
in your case b= 10 / sin 30 = 10 / .5 = 20
Upvotes: 1