Can someone please point me in the right direction with specifying an event for a function that is not continuous? For example, suppose that I have Object1 that moves along the x axis and I also have another Object2 that moves vertically at x=100.
I would like the event function to trigger whenever Object1 passes through x=100 and the distance between the two objects is say 10. The problem with this is that when the event triggers, the distance must jump from d=10 to -1 and I this doesn't work for me because the function is not continuous.
function [value, isTerminal, direction] = myEvent(t, z)
distBetweenObj = z(1)-z(2)
if abs(distBetweenObj) < tol && objectsCollider(z(1),z(2))
value = -1;
isTerminal = 1; % the event should be triggered at this point
direction = -1; % but for some reason it doesn't
else
value = distBetweenObj;
isTerminal = 0;
direction = -1;
end
end
Anyone has any ideas how I could specify this function?