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?

  • $\begingroup$ The velocity? How is this location vector defined? Parametric equation, Fcurves, ... $\endgroup$ – Omar Emara Aug 19 '18 at 7:20
  • 1
    $\begingroup$ Possible duplicate of Animation Nodes and Velocity $\endgroup$ – Omar Emara Aug 19 '18 at 7:22
  • $\begingroup$ @OmarAhmad I don't have Fcurves, the vector is a realtime data that is coming outside of blender. $\endgroup$ – Denis Aug 19 '18 at 15:39
  • $\begingroup$ 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? $\endgroup$ – Omar Emara Aug 19 '18 at 16:14
  • $\begingroup$ @OmarAhmad No, the vector data is streamed from a sensor $\endgroup$ – Denis Aug 19 '18 at 16:17

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.

  • $\begingroup$ You can also use the reassign parameter feature in the loop, which behaves the same way. $\endgroup$ – zippy Aug 21 '18 at 0:49
  • $\begingroup$ @zippy We are talking about moving data across executions, not in the same one. Loops are useless in that regard. $\endgroup$ – Omar Emara Aug 21 '18 at 7:10
  • $\begingroup$ @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. $\endgroup$ – zippy Aug 21 '18 at 13:33

Your Answer

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

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