2

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?

Denis
  • 13,059
  • 7
  • 60
  • 81

1 Answers1

2

This answer is based on my other answer about passing data between executions in Animation Nodes.

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.

Node Tree

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.

Omar Emara
  • 22,639
  • 5
  • 55
  • 103