Post Reply 
(41C) Area of Triangle (SSS)
11-10-2018, 08:53 PM (This post was last modified: 11-10-2018 09:33 PM by Dieter.)
Post: #3
RE: (41C) Area of Triangle (SSS)
(11-10-2018 12:20 PM)Gamo Wrote:  This program tell what kind of Triangle then give answer of the area.

Sorry, but this doesn't work. Try a=5, b=4 and c=3 and it returns "SCALENE". The three sides must be entered in a specific order. For instance, for right-angled triangles the largest side has to be c. Maybe you should add this in the instructions.
Also the LBL 02 part can be removed – the test whether R01=R02 has already been done before. So you may remove that section and replace "GTO 02" with "GTO 03".

(11-10-2018 03:22 PM)Albert Chan Wrote:  If the sides are sorted, a >= b >= c, Kahan's formula is more accurate.

Area Δ = 1/4 √((b+c+a)(b-a+c)(a-b+c)(b-c+a))

A sorted order also faciliates the tests for the different kinds of triangles.Here is a program that puts the largest side in R01 and the smallest in R03. It should work for any input order, and it also uses the Kahan formula.

Code:
 01 LBL "AREA"
 02 "ENTER A↑B↑C"
 03 PROMPT
 04 X>Y?
 05 X<>Y
 06 RDN
 07 X>Y?
 08 X<>Y
 09 R↑
 10 X>Y?
 11 X<>Y
 12 STO 03
 13 RDN
 14 STO 02
 15 RDN
 16 STO 01
 17 RCL 02
 18 RCL 03
 19 +
 20 RCL 01
 21 +
 22 RCL 02
 23 RCL 01
 24 -
 25 RCL 03
 26 +
 27 *
 28 RCL 01
 29 RCL 02
 30 -
 31 RCL 03
 32 +
 33 *
 34 RCL 02
 35 RCL 03
 36 -
 37 RCL 01
 38 +
 39 *
 40 SQRT
 41 4
 42 /
 43 STO 00
 44 RCL 01
 45 RCL 03
 46 "EQUILATERAL"
 47 X=Y?
 48 GTO 00
 49 RCL 01
 50 RCL 02
 51 -
 52 RCL 02
 53 RCL 03
 54 -
 55 *
 56 "ISOSCELES"
 57 X=0?
 58 GTO 00
 59 RCL 03
 60 X^2
 61 RCL 02
 62 X^2
 63 +
 64 RCL 01
 65 X^2
 66 "SCALENE"
 67 X=Y?
 68 "RIGHT-ANGLED"
 69 LBL 00
 70 RCL 00
 71 AVIEW
 72 END

The program does its tests in the following order, assuming a ≥ b ≥ c.

1. Check if a=c. This means that a=b=c => equilateral triangle
2. Check if a=b or b=c. If true, it's a isosceles triangle
    Note: line 49...55 are a kind of poor man's "OR" test
    A conventional approach would even be slightly shorter, but it looks more fancy this way ;-)
3. Check if a²=b²+c². In this case it's a right-angled triangle
4. If none of the tests was true it's a scalene triangle

Examples:

Code:
[XEQ] "AREA"    ENTER A↑B↑C
 5 [ENTER] 
 3 [ENTER] 
 4 [R/S]        RIGHT-ANGLED
   [←]          6,0000

[R/S]           ENTER A↑B↑C
 8 [ENTER] 
 3 [ENTER] 
 8 [R/S]        ISOSCELES
   [←]          11,7872

Press backspace [←] to see the area.

(11-10-2018 03:22 PM)Albert Chan Wrote:  Try Kahan's example:
a,b,c = 100000, 99999.99979, 0.00029
True Area Δ ~ 9.9999999895

For this case the result with the above program is correctly rounded to 9,999999990.
Well, almost – the true result is 9,9999 99989 49999 99... so that the ten-digit value should better be rounded down to ...989. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(41C) Area of Triangle (SSS) - Gamo - 11-10-2018, 12:20 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-10-2018 08:53 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-12-2018, 08:28 PM
RE: (41C) Area of Triangle (SSS) - Gamo - 11-11-2018, 05:04 AM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-11-2018, 07:53 AM
RE: (41C) Area of Triangle (SSS) - Gamo - 11-11-2018, 12:23 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-11-2018, 04:25 PM



User(s) browsing this thread: 1 Guest(s)