- The code already works with L=90°.
- Yes, the altitude must be the distance from point
A
to the base a
between points B
and C
, forming a right-angle with that base. The derivation made that assumption, specifically with respect to the way it used h
and a
in the second area formula 1/2 h a
. That exact formula would not apply if h
was drawn differently.
- The reason your second set of inputs resulted in a non-real answer is that sometimes a set of mathematical parameters can be inconsistent with each other and describe an impossible construct, and your
P
, h
, and L
values do exactly that. Specifically, they describe an impossible triangle.
Given an altitude h
and angle L
, the smallest perimeter P
that can be achieved is an isosceles triangle split down the middle by h
. With L=30
, this would have perimeter P = a + b + c = 2h tan15 + h/cos15 + h/cos15
, which, plugging in your h=3
, results in P=7.819
. You instead tried to use P=3+sqrt(3)=4.732
. Try using various numbers less than 7.819 (plus a little; I've rounded here) and you'll see they all result in imaginary results. That's math telling you you're calculating something that cannot exist in reality.
If you fill in the missing close parenthesis between the Y
and the /
in line 5, then your code works perfectly.
I wrote the code slightly differently from you, here's what I did:
Prompt P
Prompt H
Prompt L
HP²/(2H(1+cos(L))+2Psin(L))→Y
(HP-Ysin(L))/H→Z
Z²-4Y→D
If D<0:Then
Disp "IMAGINARY"
Stop
End
(Z+√(D))/2→C
Y/C→B
P-(B+C)→A
Disp A
Disp B
Disp C
Edit: @Gabriel, there's nothing special (with respect to this question) about the angles 30-60-90; there is an infinite number of sets of P
, h
, and L
inputs that describe such triangles. However, if you actually want to arrive at such triangles in the answer, you've actually changed the question; instead of just knowing one angle L
plus P
and h
, you now know three angles (30-60-90) plus P
and h
. You've now over-specified the triangle, so that it is pretty well certain that a randomly generated set of inputs will describe an impossible triangle. As a contrived example, if you specified h
as 0.0001 and P
as 99999, then that's clearly impossible, because a triangle with a tiny altitude and fairly unextreme angles (which 30-60-90 are) cannot possibly achieve a perimeter many times its altitude.
If you want to start with just one of P
or h
, then you can derive equations to calculate all parameters of the triangle from the known P
or h
plus the knowledge of the 30-60-90 angles.
To give one example of this, if we assume that side a
forms the base of the triangle between the 90° and 60° angles, then we have L=30
and (labelling the 60° angle as B) we have h=b
, and you can get simple equations for all parameters:
P = a + h + c
sin60 = h/c
cos60 = a/c
=> P = c cos60 + c sin60 + c
P = c(cos60 + sin60 + 1)
c = P/(cos60 + sin60 + 1)
b = h = c sin60
a = c cos60
Plugging in P=100
we have
c = 100/(cos60 + sin60 + 1) = 42.265
b = h = 36.603
a = 21.132
If you plug in P=100
, h=36.603
, and L=30
into the code, you'll see you get these exact results.