Determine direction of mouse

Hi all,

I have been trying for multiple days now to get the direction of movement of a mouse but I can’t get it to work. Maybe you would have ideas ?

Here are some questions that I had:

  • How to know if the mouse is moving backward or forward ?
  • What happens if the mouse is just going in cercle ?

I have all coordinatinates of limbs, nose, body and tail. So far, I tried with both version of v2 but the results don’t seem to work…

import numpy as np

i = current_timestamp

v1 = [float(deepcut_table['Nose_x'][i-1]) - float(deepcut_table['Body_x'][i-1]), 
                  float(deepcut_table['Nose_y'][i-1]) - float(deepcut_table['Body_y'][i-1])]
# v2 = [float(deepcut_table['Nose_x'][i]) - float(deepcut_table['Body_x'][i]), 
            #      float(deepcut_table['Nose_y'][i]) - float(deepcut_table['Body_y'][i])]
v2 = [float(deepcut_table['Body_x'][i]) - float(deepcut_table['Body_x'][i-1]),
                  float(deepcut_table['Body_y'][i]) - float(deepcut_table['Body_y'][i-1])]
scalar = np.vdot(v1,v2)

I’m a bit lost in the theoretical way of doing it but if you also have advices on how to do it in python, they are also welcome ! :slight_smile:

Thanks !


have you checked out some of the tools here?

this might be useful:

there is also a new function in 2.0.8 that analyzes the “skeleton”:

1 Like

Dear @lguerard,

You can e.g. calculate the difference vector of nose - body (at a given time) and then calculate the angle in relation to e.g. the x axis of your setup (1,0). How to calculate angles in Python is discussed here:

Hope that helps!


1 Like

Thanks for the answers, I’ll look into it and comment back once I’ve tried a couple of things

This makes sense and I guess I will have to implement that since the rotation of the mouse is also important to know what’s forward and what’s backward. But on its own it doesn’t give me the movement of the mouse does it ? :confused:

Thanks a lot for this link, I will look into those notebooks, they’re super handy ! :slight_smile:

I checked the one you sent but it’s focused on only point as far as I understood, the snout, while I need to focus on 2 (probably nose/body) for trajectory and direction :sweat_smile:

Thanks again to both of you !

To get the heading direction calculate the speed. Speed can be calculated with this:

For forward/backward you need to check if the snout or tail is leading…

You can also do the velocity vector v of the mouse and then calculate dot(v, snout-tail) this will be positive for forward and negative for backward running…