1
$\begingroup$

I'm new to the stack exchange, not so new to Blender, but new(ish) to animation nodes.

I have built a set of nodes (and some python) that reads GPS info from a CSV file and uses this data to create animated gauges to overlay on my flying videos. I'm having a problem with the compass. Whenever the heading goes through the rollover from (say) 359 deg to (say) 1 degree, the compass rotates all the way backwards through 180 deg to reach 1 deg. It does this also when transiting the rollover in the other direction. What I want to do is to have the compass smoothly transit through the rollover zone in the proper direction. I was wondering if anyone has solved a problem like this (I imagine this may happen when animating bones etc) and what is a useful approach for animation nodes. I though of identifying the quadrants of the compass as 1,2,3,4 going in clockwise fashion starting with the 0-90 quadrant as Q1 and ending with the 270-360 quadrant as Q4. Then somehow detecting the change from Q1 to Q4 or from Q4 to Q1 to change how the next position is calculated. Beyond that I'm a bit stumped and can't get my head around how to implement it in AN. Thanks in advance for any help offered. Edit: For clarification; The problem really lies in my interpolations between GPS reporting points. If one GPS report gives a heading of 359 deg and the next one gives a heading of 1 deg, the maths I'm doing for the interpolation between the two readings is what is taking the long way round the compass, but I'm not sure how to cure this. Scott...

$\endgroup$
2
  • $\begingroup$ Hello, without seeing a bit more about the node tree and such, it's hard to troubleshoot. Euler rotations are tricky when approaching full-circle turns, that's where Quaternions can help. Suggest reading about it or posting your node tree for reference $\endgroup$ – Gorgious Jun 4 at 9:35
  • $\begingroup$ Thanks: I thought of Quaternions and read a bit about them on Wiki but the maths and theory is beyond my tiny brain. I will see about posting my node tree, but I'm a little wary that I'll be subject to ridicule for my clumsy efforts. $\endgroup$ – FlyingAround Jun 5 at 5:46
1
$\begingroup$

if i understood you right, you want the shortest angle (difference) between two angles.

There is a node for that: vector angle

which does this:

Description

This node takes two vectors and computes two things:

The shortest angle between the two vectors in radian. The directed angle between the two vectors in a form of rotation quaternion.

https://docs.animation-nodes.com/documentation/nodes/vector/vector_angle/

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you for that. I am new to AN so this could be helpful. I don't fully understand it yet so I will give it a bit of a run in a test situation. Also, a bit of clarification that I thought of after I posted the above. The reporting interval from the GPS is 1 second, so I do interpolation between the samples. It is in the interpolations where I am coming unstuck. The maths is taking the compass around the long way because the maths is not taking account of the wraparound of the compass from 360 to 0. I will try out the node you suggested . Again, thanks for your help. $\endgroup$ – FlyingAround Jun 5 at 5:33
0
$\begingroup$

If your input data is a sequence of angles, let's say b_1, b_2, b_3 ... b_n and the actual values that your compass has are a_1, a_2, a_3 ... a_n, maybe you can try this:

  1. Calculate the difference using this python expression:

    DM_n = (b_n - b_(n-1) + 180) % 360 - 360 (% is modulo division)

    For small variations this will give you the variation that you should apply respect the previous value

  2. Sum DM_n to the previous value of your Blender Compass, a_n

    a_n = a_(n-1) + DM_n

The two sequences (a_n and b_n) will point to the same angle but a_n will be larger than 360 or lower than 0 depending on the turns of your data sequence

I don't know if this is what you were asking for.

$\endgroup$
1
  • $\begingroup$ Thanks for that. I don't know if it is what will do the job, but I will experiment with that. What you suggest might be the solution as I'm doing interpolations between samples that are 1 sec apart (from the GPS). Thanks for your help. $\endgroup$ – FlyingAround Jun 5 at 5:39
0
$\begingroup$

OK, so I solved this using some boolean logic. I used Compare Numbers nodes to detect if the compass is going to cross the 360/0 boundary. If that is the case, I do different types of calculations to arrive at the number of degrees to rotate and the direction (going up or down in degrees) rather than the numerical difference between the two angles. If I'm not crossing the boundary, I just work with the numerical difference in the angles. The method I use is clunky, but it works. For future reference, if anyone wants to know the nodes setup I used, PM me directly.

$\endgroup$

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.