Saturday, February 10, 2018

HP Prime Custom App: GeomCalc

HP Prime Custom App: GeomCalc

Introduction

The app GeomCalc is an example of a custom HP App for the HP Prime.  For general information, please visit this blog entry:  http://edspi31415.blogspot.com/2018/02/hp-prime-intro-to-blank-custom-apps.html

Let’s get start with this example app.

START - The Initial Conditions

Here I set the app’s angle to degrees mode.  Note that I use the variable AAngle instead of the global variable HAngle.  The values for AAngle are slightly different than HAngle:

0:  use the angle setting from Home Settings
1:  Radians
2:  Degrees
3:  Gradians

I want the app to operate with angles in degrees, so I set AAngle to 1.

The last command is a message box containing the word Ready, to let the user know that the app is all set to go. 

START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;

Info – Title and Introduction

I want to leave some basic information about this app.  I recommend that you use the PRINT command rather than the TEXTOUT/WAIT/FREEZE.  Alternatively, you can store a string in ANote. 

I prefer using PRINT because I can print multiple lines with appropriate line breaks.

Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;



The Symb section – selecting the calculation

In this section, I set the variable I to a choice of one of ten options.  The variable I is a global variable, so I can use determine calculations.  The INPUT command uses a dropdown box.  The general format for a single dropdown box is:

INPUT( { { var, {“choice 1”, “choice 2”, … }}}, … (other parameters)  )

The message box at the end let’s the user know that the choice has been set, and can now proceed to the calculation by pressing [Num]. 

Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;



The Num section – doing the calculation

When the [Num] is pressed, the user as asked to enter the arguments.  The final result is displayed on the terminal.  Since global variables (including A-Z) is used, values are permanently stored until changed.  In this app, I store the area in the variable E and the volume in V.

There is no default selection, so I use ten IF-THEN structures than a CASE structure.

Num()
BEGIN

IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;

IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;

IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;

IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;

IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;

IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;

IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

END;




Putting It All Together 

#pragma mode( separator(.,;) integer(h32) )

Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;

//Plot()
//BEGIN
// MSGBOX("Plot");
//END;

Num()
BEGIN

IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;

IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;

IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;

IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;

IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;

IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;

IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;

IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;

END;

//SymbSetup()
//BEGIN
// MSGBOX("SymbSetup");
//END;

//PlotSetup()
//BEGIN
// MSGBOX("PlotSetup");
//END;

//NumSetup()
//BEGIN
// MSGBOX("NumSetup");
//END;

Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;

START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;

//RESET()
//BEGIN
// MSGBOX("RESET");
//END;

//VIEW "Views", Views()
//BEGIN
// MSGBOX("Views");
//END;

Examples

Example 1:  Area of a Polygon



Example 2:  Volume of a Cone



I plan to post another example by next week, that one will involve plotting.


Eddie


This blog is property of Edward Shore, 2018

HHC 2025 Videos

  HHC 2025 Videos The talks from the HHC 2025 conference in Orlando, Florida are starting to be up on hpcalc’s YouTube page within th...