I have created two animations:

  • One where a "camera" moves towards the spheres creating an optic flow (1st GIF).The code can be found here.

  • One where spheres move randomly in a 3D coordinates space (2nd GIF). To do so I have computed two angles theta and phi. The code can be found here.

I need to compute the speed of each sphere frame by frame in both animations, but I have no idea of the mathematics. I would assume that the formula would be different in the two animations. I have found only the calculation of 3D velocity, and I was wondering whether I could calculate the speed as a single value?

enter image description here enter image description here

  • $\begingroup$ The formuls of speed is the same in both cases $\endgroup$
    – joojaa
    Nov 18, 2019 at 20:07
  • $\begingroup$ Can you please elaborate? $\endgroup$
    – Kathia
    Nov 18, 2019 at 21:27
  • $\begingroup$ Formula for (discrete) speed in abitrary dimension is the length or the vector from one frame to next. Length of a vector is just pythagoras theorem. $\endgroup$
    – joojaa
    Nov 18, 2019 at 21:29
  • $\begingroup$ Thanks. How is Pythagoras theorem applied in this situation? what is the speed exactly? Could you help me understand the application to my specific case? thanks in advance $\endgroup$
    – Kathia
    Nov 19, 2019 at 10:22
  • $\begingroup$ Seems like your code was deleted. Do you need velocity in screenspace, or world space? Velocity is simply rate of change of position. You could calculate the distance between two 3D positions and get a scalar speed value. $\endgroup$
    – zeno
    Nov 19, 2019 at 19:58

1 Answer 1


I'd use the euclidean distance between two 3D positions. Velocity is distance over time. Time is a single frame in this case.

$$\sqrt{(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2}$$

If you only move the camera, it is simply that frame of reference that moves, so all spheres have a relative velocity equal to the camera's velocity.

  • $\begingroup$ If I understand you well: - In the Random animation: the spheres are moving randomly in a 3D space. The formula of the speed for each sphere is the formula of the euclidean distance divided by the framerate? - In the optic flow animation: the spheres are static, but the "camera" is moving towards them from the near to the far clipping plane. "so all spheres have a relative velocity equal to the camera's velocity." Does this mean that each sphere's speed is equal to the camera speed? and is the formula of the camera speed is the euclidean distance divided by the framerate? $\endgroup$
    – Kathia
    Nov 21, 2019 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.