- Home /
Calculating triangle side length based on hypotenuse?
Essentially as part of my application the sides of a triangle are calculated much like the first part of the attached image. This is done using a simple distance function. However later in the application the triangle can be scaled (1 to 1 so it remains the same shape), I continue knowing the distance (hypotenuse) but not the side edges, I've had real trouble allowing my application to calculate the side edges (part 2 of the diagram). If anyone could help then it would be greatly appreciated.
I've attempted using basic Pythagorus (b^2 = c^2 - a^2) but my application struggles with it and responds with "NaN".
For those who are interested I'm essentially building a "Scroll wheel" into my application where an object follows your finger when it's on the scroll wheel. When it's off of the scroll wheel it still follows it but only to the edge of the circle where it then stops. So if you drag your finger around the edge of the circle then it follows it round but only to the edge of the circle.
EDIT: I've attempted the following but it doesn't work. It's set inside a block that says if distance is greater than 40 then do this:
var AngleVar = ((Vector3.Angle(Vector3(Ball.position.x,Ball.position.y, 0), Vector3(MoveDist.x, MoveDist.y, 0)))/180);
Target2.position = Vector3((40 * Mathf.Cos(AngleVar)), (40 * Mathf.Sin(AngleVar)), Target2.position.z);
It doesn't limit the distance to 40 like it should and the rotation is not correct either. AngleVar is calculated correctly. When it's directly above "Ball" (Wheel centre) it is 1 and when directly below it is 0. I realise that Sin and Cos will flip round as I move around the circle but this code is not working an any segment.
This is pretty basic, if you know the angle of the triangle you can use trigonometry to find the other sides or if you're using vectors it's a simple case of subtraction. What script did you use to get that error?
I'm not using vectors so unfortunately that will not work. I tried your solution. The results are above. I'm sure I've done something wrong ^-^
I'm having trouble figuring out what your code is doing exactly.. what is this Ball? and what is $$anonymous$$oveDist? Trig can be a bit wonky, but if you can give us a better sense of your code I can definitely help you solve this one.
In general terms you say you know all of the original sides of the triangle... and thus can find Theta (the angle of the triangle between the adjacent and hypotenuse). $$anonymous$$ake use of SOH CAH TOA (Sin(Theta) = opposite/hypotenuse etc) to find Theta for the original triangle, and then scale it appropriately... and use the Hypotenuse length and this known Theta to clone the tri
Answer by Mike 3 · Aug 05, 2010 at 03:07 PM
Not entirely sure what the issue is here - you're scaling the triangle, can't you just scale the values too?
Multiply the values from the left triangle by 30/58.0 (Hypotenuse2/Hypotenuse1) and you get the right triangle values
Example using the standard 3 4 5 triangle:
1) Hypotenuse: 5, Opposite: 3, Adjacent: 4
2) Hypotenuse: 10
To get the Opposite and Adjacent values:
Opposite = 3 * 10/5 = 6
Adjacent = 4 * 10/5 = 8
Which matches with a 6 8 10 triangle like you'd expect
Your answer
Follow this Question
Related Questions
Find position of pixel on sphere given position of pixel on texture 1 Answer
calculus help angels of a triangle 1 Answer
Why say Unity that 320* (1 / 320) = 0? 5 Answers
Calculate Position of Rigidbody after applying Force 0 Answers
Math question, center of triangle that is part of a square 1 Answer