**HP Prime and Numworks: Plotting a Parametric Line of Motion**

**Plotting
the Position of Motion**

This program draws a 2D motion plot from an initial starting point (x, y) given initial velocity and acceleration. The rate and direction of both velocity and acceleration are assumed to be constant.

x(t) = ax * t^2 / 2 + vx * t + x0

y(t) = ay * t^2 / 2 + vy * t + y0

where:

t = number of seconds.

ax = acceleration in the x direction

ay = acceleration in the y direction

vx = initial velocity in the x direction

vy = initial velocity in the y direction

The HP Prime PPL program PLOTMOTION displays a traceable curve with a table of values.

The Numworks python script plotmtn.py uses math and matplot.pyplot modules. A scatter plot is laid on top of the path plot. The plot begins at the initial point where it is marked green.

**HP
Prime Program: PLOTMOTION**

EXPORT PLOTMOTION()

BEGIN

// EWS 2024-07-22

LOCAL ch;

ch:=INPUT({C,D,A,B,V,U,N},

"Motion Plot Per Second",

{"x0:","y0:","vx:","vy:","ax:","ay:","n:"},

{"initial x position",

"initial y position",

"initial velocity x direction",

"initial velocity y direction",

"acceleration x direction",

"acceleration y direction",

"number of seconds"});

// user presses cancel

IF ch==0 THEN

KILL;

END;

// user presses OK

STARTAPP("Parametric");

'V*T^2/2+A*T+C'▶X1;

'U*T^2/2+B*T+D'▶Y1;

CHECK(1);

Parametric.Tmin:=0;

Parametric.Tmax:=N;

Parametric.Tstep:=1;

// table and plot

STARTVIEW(10);

STARTVIEW(9);

END;

**Numworks Python Code: plotmtn.py**

from math import *

from
matplotlib.pyplot import *

# 2024-07-23 EWS

print("Motion
Plot per second from (0,0)")

c=eval(input("init. x
position? "))

d=eval(input("init. y position?
"))

a=eval(input("init. x velocity?
"))

b=eval(input("init. y velocity?
"))

v=eval(input("acceleration x?
"))

u=eval(input("acceleration y?
"))

n=int(input("number of seconds?
"))

x=[v*t**2/2+a*t+c for t in
range(n)]

y=[u*t**2/2+b*t+d for t in
range(n)]

x0=min(x)-1

x1=max(x)+1

y0=min(y)-1

y1=max(y)+1

axis((x0,x1,y0,y1))

text(x0,y1-1,"Motion
Plot")

plot(x,y,'gray')

scatter(x,y,color='blue',marker="h")

scatter(x[0],y[0],color='green',marker="h")

show()

**Source**

Tremblay,
Christopher. __Mathematics
for Game Developers__.
Thomson Course Technology. Boston, MA. 2004. ISBN 1-59200-038-X.

Eddie

All original content copyright, © 2011-2024. 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.