I am trying to implement a two-dimensional proportional navigation in Netlogo as it is defined by these formulas:
where v_r is the difference in velocities, r is the line of sight and phi is the angle. Theta is supposed to be the change in line of sight and N is the navigation constant. I am using the formula with the sin since I am two-dimensional.
And I am a bit lost because the two moving objects don't collide at all in my current implementation.
So, currently I am calculating v_r and r like this, and I'm fairly sure this is correct since testing it with predefined positions/orientations yields the desired results:
;; line of sight
let rx [xcor] of target - xcor
let ry [ycor] of target - ycor
; difference in velocity components
let vx ([dx] of target * speed) - dx * predator-speed
let vy ([dy] of target * speed) - dy * predator-speed
The angle is calculated like this and should also be correct:
let dot (vx * rx + vy * ry)
let det (vx * ry - vy * rx)
set angle atan det dot
And putting it all together, theta is this:
let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt(rx ^ 2 + ry ^ 2)
And then I calculate the difference to the previously calculated theta since the first formula uses its differential, multiply it with the constant and convert it to degrees:
let delta-theta theta - theta-old
set theta-old theta
let turn-rate (delta-theta * N * 180 / pi)
turn-at-most turn-rate max-hunt-turn
When I run it, the following happens (both turtles have the same speed, one moves right, one up) (it doesn't change much for most values of N between 3 and 5)
I assume I have some mistake in understanding the last step, since I do think that the components should be fine. To put it into a question: What do I do with theta (or delta theta) in order to get a change in heading?
Edit: here is where the actual turn happens:
to turn-at-most [turn max-turn] ;; turtle procedure
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
Edit 2: current status is that I think the formula given for theta is actually the derivative of theta already, because using theta instead of delta-theta gives me the desired behavior (or at least it looks like it). I still need confirmation for this, but I'll keep the thread updated.