can anyone show me the formula to work out the lengths of 1 of the legs + the hypotenuse in a right angle triangle? i know the length of 1 of the legs in pixels + also know all 3 angles.
so assuming i know the length of side a + all 3 angles, how do i work out the length of sides b + c?
Call the angle opposite side b angle B. Using the same convention, angle C would then be 90 degrees in your setup. From there you use trig functions. The mneumonic "soh-cah-toa" helps me remember them. In this setup, "cah" means "cosine = adjacent / hypotenuse". Then we can solve for c using
cos(B) = a / c = adjacent side to angle B / hypotenuse of the triangle.
Since we know a and angle B, solve for c by cross multiplying, giving
c = a / cos(B).
From here there are three ways that come to mind to solve for side b. I'll use the Pythagorean Theorem, which says that the side lengths of a right triangle are related through
a^2 + b^2 = c^2.
Since we can get c using the above formula, and we know a, we can solve for b:
b^2 = c^2 - a^2
b = sqrt(c^2-a^2).
The time you enjoy wasting is not wasted time. Bertrand Russell
i can't get your formula to work. in the attached screenshot i'm trying to draw a line from the centre to the 12 o'clock position on the 2nd rectangle(that part is working), then another line from the centre to the 1 o'clock position on the 2nd rectangle, which is way off.
what am i doing wrong?
heres the code:
vb Code:
'351,151 - centre
'10 + sf.Height - 2nd rectangle top
'30 degrees - 1 o'clock
Dim lX2 As Single = 351 + Math.Sin(Math.PI * 30 / 180) * 351 / Math.Cos(30)
Dim lY2 As Single = 151 - Math.Cos(Math.PI * 30 / 180) * (151 - (10 + sf.Height)) / Math.Cos(30)
You've used Cos(30) twice, forgetting to convert to radians. The rest is a bit puzzling to me. For instance,
Code:
Dim lX2 As Single = 351 + Math.Sin(Math.PI * 30 / 180) * 351 / Math.Cos(30)
Should probably be
Code:
Dim lX2 As Single = 351 + b / Math.Cos(Math.PI * 30 / 180)
where b is the length of the vertical red line. This comes from my formula above, noting that you can just swap a, b, A, and B for an analogous problem.
The time you enjoy wasting is not wasted time. Bertrand Russell
Yup, I understood what lx2 and ly2 were. I confused the hypotenuse and opposite side, though, in my previous post--doh! I could use my two formulas together to get the correct x offset, but using the tangent function is shorter so I'll do that. It's the second of the three possible solutions I mentioned at first to solving for the length of the unknown leg of the triangle.
Since tangent = opposite / adjacent, tan(30 degrees) = x offset / b where b is the red vertical line's length. In Paint I found b=105 pixels; this is probably 10 + sf.Height - 151, though I don't use .NET. Then, the x offset is b*tan(30 degrees), or
The y offset is simply b, so ly2 = 151 - 105 = 46. I've drawn a line from (351, 151) to (412, 46) on the attached image in blue, which is I believe what you're after. One important thing to note, though, is that if you want the blue line I've drawn to "lock" to the outer rectangle, you'll have to use different equations for each side of the rectangle, since your triangle problem changes each time.
The time you enjoy wasting is not wasted time. Bertrand Russell
Yes, I wrote tan(30 degrees), though programming languages don't use units in their numbers. I could have said tan(1800 minutes) for the same thing, since 30 degrees = 30*60 or 1800 minutes. The upshot of it is, .NET wants you to use tan(___ radians), so you have to convert to radians.
The time you enjoy wasting is not wasted time. Bertrand Russell