# Compute spheres 2D speeds in perspective projected animations

I created two animations that consist of spheres moving in a perspective projected 3D space, which means that the size and speed of the spheres vary with the distance: they increase when they are closer to the viewer (the camera) and decrease when they move farther away from the viewer. Both animations are played on a computer 2D screen.

In the Random Movement Animation, the spheres are moving randomly in different directions (GIF 1). In my code, I computed their spherical coordinates (sphere.position.xyz) with the two angles theta and Phi (see below the formulas used for the position and their derivates).

In the Optic Flow Animation, it is the camera that moves along the z-axis (camera_z -= .1) and the spheres don't move (GIF 2).

In the context of a neuroscientific experiment, I need to match the perception of speed between the two animations, thus I need to first compute the 2D speed in both animations (By 2D, I refer to the screen coordinates rather than the world coordinates). What are the respective speed formulas for each animation? Does the speed of each sphere in the optic flow calculation equal to the camera's speed?  How I generated Spheres coordinates in the Random animation:

for sphere in spheres:

sphere.position.xy = np.random.uniform(-25, 25, size=2)
z = np.random.uniform(near_z, far_z)

sphere.position.z = z
sphere.position.x *= z/-50
sphere.position.y *= z/-50

sphere.theta_deg = np.random.rand(1) * 360
sphere.phi_deg = np.random.rand(1) * 360

theta_rad = sphere.theta_deg * np.pi / 180
phi_rad = sphere.phi_deg* np.pi / 180