HP Prime: Pixel Plot, How to Change Cartesian Coordinates to Pixels
Changing Cartesian Coordinates to Pixels
When running programs on the HP Prime, the screen has a pixel coordinate system of 320 x 220 (to allow room for soft menu keys).
There are two ways to calculate to translate Cartesian coordinates to pixel coordinates on the HP Prime. The easy way is to use the C→PX command.
However, if you are working in custom made apps, C→PX may not work because the command requires that app has the Plot variables Xmin, Xmax, Ymin, and Ymax. This will require a conversion formula.
Given a desired xmin, xmax, ymin, and ymax, the following formulas I use are:
xs = (xmax – xmin)/320
ys = (ymax – ymin)/-220 = (ymin – ymax)/220
Conversion to pixels of coordinates (x,y):
xp = (x – xmin)/xs
yp = (y – ymax)/ys
HP Prime Program: PIXELPLOT
// EWS 2014-02-04
// set color scheme
"Pixel Plot Official",
"x-min: ","x-max: ",
"y-min: ","y-max: ",
// calulate the scale
// color choice
// axis information
FOR x FROM xm TO xn STEP xs DO
// skip 0 for now
IF x==0 THEN
// point→pixel, plot
// only if y is real
IF TYPE(y)==0 THEN
// freeze screen
1. You should not have to include the string characters for f(x) as they are included in the input.
2. Use the lowercase x.
3. The program errors if a plot reaches point where f(x) is not defined. I put in a condition when f(x) is complex (for example, the square root of negative number) for the plot to skip that pixel. However, I have not put error skipping conditions when it comes to ln(x) or 1/p(x) where p(x) is a polynomial. However, the pixel at x=0 is skipped to hopefully alieve some problems. Be sure your range is appropriate.
4. The program uses Radians angle mode (HAngle = 0).
5. I chose to have a black background with five color options (purple, electric blue, green, gold, and red) just for fun.
Example 1: f(x) = 2.5*cos(x^2)
Example 2: f(x) = √(x^2 – 6)
Example 3: f(x) = e^(-x^2)
This blog is property of Edward Shore, 2018.