Showing posts with label Heron's Formula. Show all posts
Showing posts with label Heron's Formula. Show all posts

Sunday, November 22, 2020

Heron's Formula vs Area by Vertices

Heron's Formula vs Area by Vertices

There are several ways to determine the area of a triangle.

Heron's Formula:

With side lengths A, B, and C, the area is:

Area = √( S * (S - A) * (S - B) * (S - C) ) 

where S = (A + B + C) / 2

Area of Vertices:

With vertices (x1, y1), (x2, y2), and (x3, y3), the area is:

Area = 1/2 * abs( (x1 - x2) * (y1 + y2) + (x2 - x3) * (y2 + y3) + (x3 - x1) * (y3 + y1) )

Testing The Data






I ran a test of 50 randomly selected sets of three points that form the triangle.  The three points are:
*  The origin: (0,0)
*  The second point has 0 ≤ x ≤ 20 and -20 ≤ y ≤ 20, x and y are integers
*  The third point has 0 ≤ x ≤ 20 and 0 ≤ y ≤ 20, x and y are integers

I used the Casio fx-9750gIII Spreadsheet application.    

Casio Spreadsheet Set Up

Column Titles - Row 1:

Column A:  "X1"   x coordinate of point 1
Column B:  "Y1"   y coordinate of point 1
Column C:  "X2"   x coordinate of point 2. 
Column D:  "Y2"  y coordinate of point 2
Column E:  "X3"  x coordinate of point 3
Column F:  "Y3"  y coordinate of point 3
Column G:  "XY1"  distance between points 1 and 2
Column H:  "XY2"  distance between points 2 and 3
Column I:  "XY3"  distance between 3 and 1
Column J:  "S"   semi-perimeter of the triangle
Column K:  "HERON"  Area by Heron's Formula
Column L: "VERT"  Area by Vertices 
Column M:  "DIFF"  Difference between two calculation methods

Formulas for Rows 2 through 51

Column A:  A2 = Fill(0,50)
Column B:  B2 =Fill(0,50)
Column C:  C2 =Seq(Int(22 Ran#) - 1,X,1,50,1)
Column D:  D2 =Seq(Int(41 Ran#) - 21,X,1,50,1)
Column E:  E2 =Seq(Int(22 Ran#) - 1,X,1,50,1)
Column F:  F2 =Seq(Int(22 Ran#)-1, X,1,50,1)
Column G:  G2 Fill:  =√(C2^2 + D2^2) for range G2:G51*
Column H:  H2 Fill:  =√((C2-E2)^2 + (D2-F2)^2) for range H2:H51
Column I:  I2 Fill:  =√(E2^2 + F2^2) for range I2:I51*
Column J: J2  Fill:  =(G2 + H2 + I2) ÷ 2 for range J2:J51
Column K:  K2 Fill =√(J2 (J2 - G2) (J2 - H2) (J2 - I2) ) for range K2:K51
Column L:  L2 Fill =0.5 × Abs( (A2 - C2)(B2 + D2) + (C2 - E2)(D2 + F2) 
+ (E2 - A2)(F2 + B2)) for range L2: L51
Column M:  M2  Fill =K2-L2

 * To take advantage that the first point is (0, 0).  The full distance formula would be needed otherwise.  

This spreadsheet implies that there is no "rounding" the middle results.  


If you want to download the spreadsheet results, click here:


The zip file contains two images, a csv file, and a Casio spreadsheet file that can be ran on Casio calculators with a spreadsheet application. 

Of the sample taken, the areas determined by Heron's Formula and Area by Vertices are substantially equal; any difference is the order of 10^-12.

Happy Thanksgiving,

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 

Saturday, September 15, 2018

HP 20S and 21S: Heron's Triangle

HP 20S and 21S:  Heron's Triangle

Introduction

The following program calculates the area of a triangle knowing the three lengths.  The area is determined by Heron's formula:

Area:  √(s * (s - a) * (s - b) * (s - c)) where s = (a + b + c)/2
Store the lengths of the triangle in registers R0, R1, and R2 respectively.  
Results are stored in the following registers:
R3:  s
R4:  area

HP 20S and 21S Program: Heron's Triangle

The key codes for both calculators are the same.

STEP KEY KEY CODE
01 LBL A 61, 41, A
02 RCL 0 22, 0
03 STO 3 21, 3
04 RCL 1 22, 1
05 STO+3 21, 75, 3
06 RCL 2 22, 2
07 STO+3 21, 75, 3
08 2 2
09 STO÷3 21, 45, 3
10 RCL 3 22, 3
11 STO 4 21, 4
12 RCL 3 22, 3
13 - 65
14 RCL 0 22, 0
15 = 74
16 STO×4 21, 55, 4
17 RCL 3 22, 3
18 - 65
19 RCL 1 22, 1
20 = 74
21 STO×4 21, 55, 4
22 RCL 3 22, 3
23 - 65
24 RCL 2 22, 2
25 = 74
26 STO×4 21, 55, 4
27 RCL 4 22, 4
28 11
29 STO 4 21, 4
30 RTN 61, 26

Example

R0 = 17, R1 = 18, R2 = 21.   Result:  Area:  148.833238744

Note:  I switched computers last week.  For the last few years, I used Microsoft Word but for the time being I am going to use WordPad.  Let's see how this goes.  Fortunately I can still can use Unicode characters with Alt+X.  For example, I can type 221A, then type [Alt] + [ X ] to get the square root character.  Unfortunately, WordPad doesn't have spell check.  

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.


Saturday, August 20, 2016

HP 12C: Heron’s Formula, Ulam’s Conjecture, and Prime Factorization

HP 12C:  Heron’s Formula, Ulam’s Conjecture, and Prime Factorization

The following programs have been ported to the HP 12C from various programs presented in the 1980 book, “Programmable Pocket Calculators” by Henry Mullish and Stephen Kochan.  Please see the reference at the end of this entry.

HP 12C:  Heron’s Formula

Heron’s Formula calculates the area of a triangle with side measurements a, b, and c.  

Area = √( s * (s-a) *(s-b) *(s-c)), with s = (a + b + c)/2

Based on the original program for HP 67 (pg. 170 of Source)

STEP
CODE
KEY
01
44, 1
STO 1
02
31
R/S
03
44, 2
STO 2
04
31
R/S
05
44, 3
STO 3
06
45, 1
RCL 1
07
40
+
08
45, 2
RCL 2
09
40
+
10
2
2
11
10
÷
12
44, 4
STO 4
13
45, 1
RCL 1
14
30
-
15
45, 4
RCL 4
16
20
*
17
45, 4
RCL 4
18
45, 2
RCL 2
19
30
-
20
20
*
21
45, 4
RCL 4
22
45, 3
RCL 3
23
30
-
24
20
*
25
43, 21
26
43, 33, 00
GTO 00

Instructions:

Input a, press [R/S], input b, press [R/S], input c, [R/S].  The area will be calculated.

Test 1:  a = 4.00, b = 5.00, c = 3.00  Result:  6.00

Test 2:  a = 10.00, b= 15.00, c = 20.00   Result:  72.62
Test 3:  a = 7.00, b = 8.00, c = 9.00  Result:  26.83

HP 12C:  Ulam’s Conjecture

This program counts the many steps needed to reduce a positive integer to 1, by the following rules:

If the integer is even, divide by 2.
If the integer is odd, multiply it by 3 and add 1.
If the next integer is 1, stop.

Based on the original program for HP 33E (pg. 239 of Source)

STEP
CODE
KEY
01
42, 0
FIX 0 ( [ f ], 0)
02
44, 1
STO 1
03
0
0
04
44, 0
STO 0
05
1
1
06
45, 1
RCL 1
07
30
-
08
43, 35
x=0
09
43, 33, 28
GTO 28
10
45, 1
RCL 1
11
2
2
12
10
÷
13
43, 24
FRAC
14
43, 25
x=0
15
43, 33, 32
GTO 22
16
45, 1
RCL 1
17
3
3
18
20
*
19
1
1
20
40
+
21
43, 33, 23
GTO 23
22
43, 36
LSTx
23
43, 31
PSE
24
44, 1
STO 1
25
1
1
26
44, 40, 0
STO+ 0
27
43, 33, 05
GTO 05
28
45, 0
RCL 0
29
42, 2
FIX 2 ( [ f ], 2)
30
43, 33, 00
GTO 00

Instructions:

Enter the integer, press [R/S].  The number of steps is calculated.
Test 1:  5 takes 5 steps to get to 1 through Ulam’s Conjecture.
Test 2:  21 takes 7 steps to get to 1 through Ulam’s Conjecture.
Test 3: 39 takes 34 steps to get to 1 through Ulam’s Conjecture.

HP 12C Prime Factorization

This is the prime factorization of a prime integer.  The program ends when the original integer is returned, and FIX 2 mode is set.  Another change I made was instead of the pause command in the original program, I made it a run/stop command so that you write down the prime factors at your leisure. 

Based on the original program for HP 25/25C (pg. 77 of Source)

STEP
CODE
KEY
01
42, 0
FIX 0  ( [ f ], 0 )
02
44, 2
STO 2
03
44, 0
STO 0
04
2
2
05
44, 1
STO 1
06
45, 0
RCL 0
07
45 ,1
RCL 1
08
10
÷
09
36
ENTER
10
43, 24
FRAC
11
43, 35
x=0
12
43, 33, 16
GTO 16
13
1
1
14
44, 40, 1
STO+ 1
15
43, 33, 06
GTO 06
16
45, 1
RCL 1
17
31
R/S
18
33
R-down, R↓
19
33
R-down, R↓
20
44, 0
STO 0
21
1
1
22
30
-
23
43, 35
x=0
24
43, 33, 26
GTO 26
25
43, 33, 06
GTO 06
26
45, 2
RCL 2
27
42, 2
FIX 2 ( [ f ], 2)
28
43, 33, 00
GTO 00

Instructions:  Enter the integer, press [R/S].  Each factor is displayed, while in FIX 0 mode.  Press [R/S] for each factor.  If the number is prime, then only the integer is shown.
Test 1: 100.   Results: 2, [R/S], 2, [R/S], 5, [R/S], 5, [R/S], 100.00
100 = 2^2 * 5^2

Test 2:  255.  Results:  3, [R/S], 5, [R/S], 17, [R/S], 255.00
255 = 3 * 5 * 17

Test 3:  11.  Results: 11 [R/S], 11.00
11 is prime

Source:

Mullins, Henry and Stephen Kochan.  Programmable Pocket Calculators  Hayden Book Company.  Rochelle Park, NJ  1980.

Eddie


This blog is property of Edward Shore, 2016.

Earth's Radius by Latitude

Earth's Radius by Latitude Introduction: Calculating the Earth’s Radius In quick, general calculations, we assume that the...