# How to calculate a difference between current and previous location vectors using animation nodes?

In my node tree I have a location vector that is streamed from a sensor, how would I calculate a difference between current and previous location vectors using animation nodes?

• The velocity? How is this location vector defined? Parametric equation, Fcurves, ... – Omar Emara Aug 19 '18 at 7:20
• Possible duplicate of Animation Nodes and Velocity – Omar Emara Aug 19 '18 at 7:22
• @OmarAhmad I don't have Fcurves, the vector is a realtime data that is coming outside of blender. – Denis Aug 19 '18 at 15:39
• So you are parsing some file containing the location vectors and you want to compute the difference between vectors across frames? Can you share some more information about your setup? – Omar Emara Aug 19 '18 at 16:14
• @OmarAhmad No, the vector data is streamed from a sensor – Denis Aug 19 '18 at 16:17

We store the vector list received from the sensor in memory by storing it in an attribute in the AN python module using this command:

AN.sensorLocations = sensorLocations


At the next execution, if we get the data at AN.sensorLocations it will be that of the last execution. And thus, if we subtract it from the data received from the sensor we will get the information we want. So, the node tree is as follows.

Where the output of the subtract node is the output we require. To avoid any confusion due to order of execution of nodes, we use the output of the subtract node as a dummy variable (A non used variable) _ in the expression node that stores the data. This ensures the subtract node executes before the expression node.

The initial execution will face an error due to the fact that there is no data in AN.sensorLocations, but this error disappear at later executions which is fine in our case because the sensor provide an up-to-date information about the location.

• You can also use the reassign parameter feature in the loop, which behaves the same way. – zippy Aug 21 '18 at 0:49
• @zippy We are talking about moving data across executions, not in the same one. Loops are useless in that regard. – Omar Emara Aug 21 '18 at 7:10
• @OmarAhmad I misunderstood. When OP wrote "vector data is streamed from a sensor" I thought AN would be running/looping to respond to live data. – zippy Aug 21 '18 at 13:33