简体   繁体   中英

Determine length from triangle

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!

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 - BC = 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

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 (ie, the blue length) divided by the length of the hypotenuse (ie, 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);

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM