astrogirl77
Programmer
Help - a Different sort of Triangle Value Calculation
I'm looking for some help with computing values of a triangle and then drawing it to screen
Known;
Two points in degrees exist on a circle
Two line lengths representing ;
base, adjacent side (a)
and
opposite (c)
we want to derive side (b) hypotenuse
and also angles (A), (B), (C)
We already know that sides (a) and (c) join and we know that the longest side length will not exceed the diameter of the circle that the triangle is circumscribed within
The triangle created will be variable as different degrees and side lengths are entered, typically this will be scalene triangles but the may also be at times right triangles
I've been using a derived arc cos function ;
------------------------------------------------------------------------
Public Function Arccos(X As Double) As Double
Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function
------------------------------------------------------------------------
I know we can convert degrees to radians via "* Pi) / 180"
I know I can get the hypotenuse by;
------------------------------------------------------------------------
side_b_squared = CDbl(c1 ^ 2 + a1 ^ 2 - (c1 * a1)) * Cos(angle_B_degree_value_radians)
b1 = Sqr(side_b_squared)
------------------------------------------------------------------------
I know we can get the angles A,B,C via ;
------------------------------------------------------------------------
angle_C_cos_value = CDbl(a1 ^ 2 + b1 ^ 2 - c1 ^ 2) / (2 * (a1 * b1))
angle_B_cos_value = CDbl(c1 ^ 2 + a1 ^ 2 - b1 ^ 2) / (2 * (c1 * a1))
angle_A_cos_value = CDbl(b1 ^ 2 + c1 ^ 2 - a1 ^ 2) / (2 * (b1 * c1))
angle_C_acos_value = (Arccos(angle_C_cos_value))
angle_B_acos_value = (Arccos(angle_B_cos_value))
angle_A_acos_value = (Arccos(angle_A_cos_value))
angle_C_degree_value = angle_C_acos_value * 180 / Pi
angle_B_degree_value = angle_B_acos_value * 180 / Pi
angle_A_degree_value = angle_A_acos_value * 180 / Pi
------------------------------------------------------------------------
Although, I've had some trouble with this since some of the returned angles for some previous testing I did didn't
seem to be working very well, for instance I'd enter 60 degrees for angle (B) but it would somehow crunch it to
angle_B_Degree Value 38.8700377933938
I'm a little stuck on the math for all this.... here is an example scenario that I hope illustrates really clearly what I'm trying to do ;
A small VB app does the following ;
A small circle is drawn to the screen
On the form of the VB app there are text boxes that accept inputs ;
Text 1 = side (c) length as a number
Text 2 = side (a) length as a number
Text 3 = a value in degrees that represents a point of one of the ends of side (c)
Text 4 = a value in degrees that represents a point of one of the ends of side (a)
Then the following are computed ;
side length of the hypotenuse as a number, and output to a different text box
Angles (A), (B), (C) are computed as values in degrees, and output to another text box
The drawn circle may be say four inches in diameter, and all side lengths computed, regardless of their number value
are fit proprotionally, circumscribed within the circle, so even if one of the side lengths is really long, all side lengths are fit proportionally in the circle but retaining the same intrinsic unit measure values of their lengths.
Any help or insights on the above are really appreciated, especially the math and formula end and any code ideas, samples are a God send.
I'm a bit of a newbie with all this and I'm using an older version of VB (4.0)
I have a basic idea on using some of the draw functions and I think I can tinker my way through this, but again am very open to any feedback
Thanks people!