function [value,isterminal,direction] = eventRRr(t,x) global L1 L2 q10 q20 deltar delta = L1*sin(x(1))+L2*sin(x(3))-(L1*sin(q10)+L2*sin(q20)); vt = -L1*x(2)*sin(x(1))-L2*x(4)*sin(x(3)); value = delta - deltar ; isterminal = 1 ; direction = 0 ; % value(i) is the value of the ith event function. % % isterminal(i)=1 if the integration is to terminate at a zero of this event function, otherwise, 0. % % direction(i)= 0 if all zeros are to be located (the default) % +1 if only zeros where the event function is increasing % -1 if only zeros where the event function is decreasing