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:
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.
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
answered Aug 05 '10 at 03:07 PM