Pixel Plot, How to Change Cartesian Coordinates to Pixels
|
02-06-2018, 02:13 PM
Post: #1
|
|||
|
|||
Pixel Plot, How to Change Cartesian Coordinates to Pixels
Blog Post: https://edspi31415.blogspot.com/2018/02/...hange.html
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: Scaling: 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 Code:
Notes: 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. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)