Showing posts with label area by vertices. Show all posts
Showing posts with label area by vertices. 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. 

Sunday, July 1, 2018

Casio fx-CG 50 and HP Prime: Pyramid Constructed by Points


Casio fx-CG 50 and HP Prime:  Pyramid Constructed by Points



The program PYRAPTS calculates the surface area and volume of a pyramid that is defined by its vertex points.  The program assumes all the points of its base lies on the plane z = 0, and there is only one tip point.

All of the base points, B1, B2, B3, B4, etc., are entered as two coordinates, one list for the X coordinates and the other for the corresponding Y coordinates.  Keep in mind that for this program, all of its base points lie on the plane Z=0.

The coordinates for the tip point, T, are prompted separately. 

Casio fx-CG 50 Program PYRAPTS (text file)

'ProgramMode:RUN
"2018-06-24 EWS"
ClrText
Red Locate 1,1,"FOR THE BASE, Z=0"
For 1->J To 1000
Next
"X _List _"?->List 1
"Y _List _"?->List 2
Dim List 1->N
"TIP X COORD="?->X
"TIP Y COORD="?->Y
"TIP Z COORD="?->Z
0->S
List 1[1]*List 2[N]-List 1[N]*List 2[1]->R
For 2->J To N
R+List 1[J]*List 2[J-1]-List 1[J-1]*List 2[J]->R
Sqrt(Z^<2>+(Y-List 2[J])^<2>+(X-List 1[J])^<2>)->A
Sqrt(Z^<2>+(Y-List 2[J-1])^<2>+(X-List 1[J-1])^<2>)->B
Sqrt((List 2[J]-List 2[J-1])^<2>+(List 1[J]-List 1[J-1])^<2>)->C
(A+B+C)/2->H
S+Sqrt(H(H-A)(H-B)(H-C))->S
Next
Abs R/2->R
S+R->S
RZ/3->V
ClrText
Blue Locate 1,1,"SURFACE AREA="
Red Locate 1,2,S
Blue Locate 1,4,"VOLUME="
Red Locate 1,5,V

Notes:
1.  - >  is the storage arrow →
2.  ^<2> is the square key x^2
3.  If you type in the program manually, the line ‘ProgramMode:RUN is not needed
4.  _ represents the space key

HP Prime Program PYRAPTS

EXPORT PYRAPTS()
BEGIN

// 2018-06-25 EWS
// pyramid by points

LOCAL L1,L2,X,Y,Z;
LOCAL S,V,R,J,N;

INPUT({{L1,[[6]]},
{L2,[[6]]}},"Base Points: Z=0",
{"X List:","Y List:"});

N:=SIZE(L1);

INPUT({X,Y,Z},"Tip Coordinates",
{"X: ","Y: ","Z: "});

S:=0;
R:=L1(1)*L2(N)-L1(N)*L2(1);

FOR J FROM 2 TO N DO
R:=R+L1(J)*L2(J-1)-L1(J-1)*L2(J);
A:=√(Z^2+(Y-L2(J))^2+
(X-L1(J))^2);
B:=√(Z^2+(Y-L2(J-1))^2
+(X-L1(J-1))^2);
C:=√((L2(J)-L2(J-1))^2
+(L1(J)-L1(J-1))^2);
H:=(A+B+C)/2;
S:=S+√(H*(H-A)*(H-B)*(H-C));
END;

R:=ABS(R)/2;
S:=S+R;
V:=R*Z/3;

PRINT();
PRINT("Surface Area: "+S);
PRINT("Volume: "+V);
RETURN {S,V};

END;

Example

Base points:  (0,0,0),  (3,4,0),  (-3,4,0)  (z=0 is implied for base points)
Tip point:  (0,1,√2)

Input:
List X:  {0, 3, -3}
List Y:  {0, 4, 4}
Tip X: 0
Tip Y: 1
Tip Z: √2

Results:
Surface Area: 25.7904472451
Volume:  5.65685424947

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.

Sunday, June 15, 2014

HP 15C: Area by Verticies With Curve Segments (with Jason Foose)

Introduction

On June 6, 2014, I posted a revised program for the HP 15C to find the area of a polygon by given the coordinates of each vertex. You can see this post here:

http://edspi31415.blogspot.com/2014/06/hp-15c-area-of-polygon-by-vertices.html

Jason Foose, County Surveyor at Mohave County Public Works in Kingman, AZ contributed an addendum to the program:  this allows you to enter curve segments and calculate the total area based on vertices and the curve segments.  Jason Foose can be found on Google+ and on Linkedin. 

General Instructions

The idea is to first enter all the coordinates of the vertices and calculate the area, then enter the curve segments and recalculate the area.  Start at one at one point and work in either the clockwise or the counterclockwise motion.  

Hence:

1.  Enter initial coordinates (x0, y0):  y0 ENTER x0 LBL A
2.  Enter additional coordinates:  y ENTER x LBL B
3.  Calculate area with coordinates:  LBL C
4.  Enter radius and central angle, in HMS format:   radius ENTER angle LBL D
5.  Calculate final area:  LBL E

When entering the radius and central angles, use positive values for radius for "outies", chord lines that add to the area.  Use negative values for "innies", or chords that cut across the area.   The 15C should be in Degrees mode. 

The Expanded Program

Here is the program in full.  Instructions in bold red are contributed by Jason Foose.  


Memory registers used:
R0 = area
R1 = x_i
R2 = y_i
R3 = x_i+1
R4 = y_i+1
R5 = Σ (x_i * y_i+1) // ( i=1...n and cycle back to 1)
R6 = Σ (x_i+1 * y_i)
R7 = x_1
R8 = y_1


Program:


001   42, 21, 11   LBL A  // enter initial vertex
002            0       0
003       44   5   STO 5

004       44   6   STO 6
005           33   R down // R↓
006       44   1   STO 1
007       44   7   STO 7
008           33   R down
009       44   2   STO 2
010       44   8   STO 8
011       43  32   RTN

012   42, 21, 12   LBL B // step 12 - add verticies
013       43   3   STO 3
014   45, 20,  2   RCL× 2
015   44, 40,  6   STO+ 6
016           33   R down
017       44   4   STO 4
018   45, 20,  1   RCL× 1
019   44, 40,  5   STO+ 5

020       45   4   RCL 4
021       44   2   STO 2
022       45   3   RCL 3
023       44   1   STO 1
024       43  32   RTN

025   42, 21, 13   LBL C // step 25 - calculate area with vertices
026       45   7   RCL 7
027   45, 20,  2   RCL× 2
028   44, 40,  6   STO+ 6
029       45   8   RCL 8
030   45, 20,  1   RCL× 1
031   44, 40,  5   STO+ 5
032       45,  5   RCL 5
033   45, 30,  6   RCL- 6
034       43  16   ABS
035            2   2
036           10   ÷
037       44   0  STO 0

038            4   4   // where Jason's steps start
039            3   3
040            5   5
041            6   6
042            0   0
043           10   divide ÷  // convert to acres
044        43 32   RTN
045   42, 21, 14   LBL D  // step 45 - segment routine
046       43   2   >HR  
047           36   ENTER
048       42   3   >RAD
049           34   X<>Y
050           23   SIN
051           30   -
052           48   DECIMAL POINT (.)
053            5   5
054           20   *
055           34   X<>Y
056       43  11   XSQ (x^2)
057           20   *
058   44, 40,  0   STO+0
059       43  32   RTN
060   42, 21, 15   LBL E  // step 60 - convert area to acres
061       45   0   RCL 0
062            4   4
063            3   3
064            5   5
065            6   6
066            0   0
067           10   DIVIDE ÷
068       43  32   RTN
Example (Updated 6/29/2014)
 
See the diagram below.  The steps are included with the diagram.  We are going to start at the point (100,100) and go counterclockwise.  The diagram and example has been provided by Jason Foose.


 
Calculate the area with the segments:

Keystrokes:

Starting at Point (100, 100)

Coordinates:
100 ENTER 100 LBL A
100 ENTER 400 LBL B
200 ENTER 500 LBL B
300 ENTER 500 LBL B
300 ENTER 225 LBL B
425 ENTER 100 LBL B
LBL C   \\ Area:  1.9011 acres

Add segments:
100 ENTER 90 LBL D \\ "outie"  angle = 90
125 ENTER 90 CHS LBL D  \\ "innie" angle = -90
LBL E   \\ Area:  1.8643 acres

Special thanks to Jason Foose for the great addendum to the area by vertices program.  

Eddie


HP 42S/DM42/Free 42: Two Functions Programmed Three Different Ways

HP 42S/DM42/Free 42: Two Functions Programmed Three Different Ways Introduction In 1979, Electro Scientific Industries (esi)...