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

<p><span class="math-container">$$\sqrt{(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2}$$</span></p>

<p>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.</p>

CC BY-SA 4.0
2019-11-21T09:55:38.030Z
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?
Kathia
CC BY-SA 4.0
2019-11-19T20:14:48.730Z
2019-11-19T20:14:48.730Z
zeno
<p>I have created two animations:</p>

<ul>
<li><p>One where a "camera" moves towards the spheres creating an optic flow (1st GIF).The code can be found <a href="https://www.codepile.net/pile/7pvd7rGJ" rel="nofollow noreferrer">here</a>.</p></li>
<li><p>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 <a href="https://www.codepile.net/pile/vWz91BKA" rel="nofollow noreferrer">here</a>.</p></li>
</ul>

<p>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?</p>

<p><a href="https://i.sstatic.net/RKv9T.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RKv9T.gif" alt="enter image description here"></a>
<a href="https://i.sstatic.net/ETe7F.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ETe7F.gif" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-11-18T20:07:30.237Z
The formuls of speed is the same in both cases
joojaa
CC BY-SA 4.0
2019-11-18T21:27:12.323Z
Can you please elaborate?
Kathia
CC BY-SA 4.0
2019-11-18T21:29:56.247Z
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.
joojaa
CC BY-SA 4.0
2019-11-19T10:22:08.200Z
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
Kathia
CC BY-SA 4.0
2019-11-19T19:58:09.830Z
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.
zeno
CC BY-SA 4.0
2019-11-21T09:45:15.073Z
@zeno The random spheres code is https://www.codepile.net/pile/Nj25dX36, and the optic flow code is https://www.codepile.net/pile/45NdxByK. I am very new to computer graphics, and I projected the world space on the screen, I would assume I have to calculate the speed on the screen? It is for a Neuroscience experiment, and I'd like to have the same speed perception between the two animations.
Kathia
CC BY-SA 4.0
2019-11-23T21:44:51.060Z
@Kathia then you have a problem. The parallax effects necessitates that the spheres move at different speeds.
joojaa
<3d><transformations><animation>
Compute Speed of Spheres in 3D animation
Kathia
# Compute Speed of Spheres in 3D animation

(Asked by: username_0 on 2019-11-18)

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](https://www.codepile.net/pile/7pvd7rGJ).
* 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](https://www.codepile.net/pile/vWz91BKA).

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](https://i.sstatic.net/RKv9T.gif)](https://i.sstatic.net/RKv9T.gif)
[![enter image description here](https://i.sstatic.net/ETe7F.gif)](https://i.sstatic.net/ETe7F.gif)

**Tags:** 3d, transformations, animation

> **Comments:**
> **username_1**: The formuls of speed is the same in both cases  
> **username_0**: Can you please elaborate?  
> **username_1**: 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.  
> **username_0**: 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  
> **username_2**: 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.  
> **username_0**: @username_2 The random spheres code is https://www.codepile.net/pile/Nj25dX36, and the optic flow code is https://www.codepile.net/pile/45NdxByK. I am very new to computer graphics, and I projected the world space on the screen, I would assume I have to calculate the speed on the screen? It is for a Neuroscience experiment, and I'd like to have the same speed perception between the two animations.  
> **username_1**: @username_0 then you have a problem. The parallax effects necessitates that the spheres move at different speeds.  

---

## 1 answers

### Answer by username_2 on 2019-11-19. Score: 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.

> **Comments:**
> **username_0**: 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?  

---

