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?

enter image description here

enter image description here

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

        sphere.dx = speed * np.sin(-phi_rad - theta_rad) / frameRate
        sphere.dy = -speed * np.cos(phi_rad + theta_rad) / frameRate
        sphere.dz = -speed * np.cos(theta_rad) / frameRate
  • \$\begingroup\$ Is it necessary to use spherical coordinates here? This will make the calculation more complicated than using 2D Cartesian coordinates (like pixel position), if quantifying motion in screen space is your ultimate goal. Note that a 1° change in angle in spherical coordinates amounts to fewer pixels of travel near the center of the screen, and more pixels of travel at the periphery. But if you're trying to measure how fast the player needs to rotate their eyeball to keep fixation on a particular particle, then a single angular speed might be more appropriate, rather than two angular components. \$\endgroup\$
    – DMGregory
    Jan 27 '20 at 21:35
  • \$\begingroup\$ @DMGregory I used the spherical coordinates to create a random movement in a random direction in the fake 3D space. I am open to simpler ways to do it if that facilitates the calculation of speed. I also still don't know how to calculate the speed. Do you have any hints on how I could perform the calculation? \$\endgroup\$
    – Kathia
    Jan 28 '20 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.