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.