MATLAB: Make axis reflective so line moves in opposite direction

homeworkMATLABreflect;reflection

I have a line that is plotted using user input:
plot(xClic, yClic,'');
hold on
% Compute y intercept for slope of 1
b = yClic*xClic;
% Plot the line between the click point and the y intercept
batBeam=plot([xClic,0],[yClic,b],'b');
The limit of the x and y axis is 100. The line stops plotting when x=0 and y=whatever or when x=whatever and y=0.
How do I make a reflective boundary that activates once the line ends at (0,y) or (x,0) that stops after two bounces. For trouble visualizing, think of a laser boucing off a mirror.
This should happen at the endpoint. The line should have the same slope and move in the opposite direction.

Best Answer

You cannot do what you are asking. It is not possible to get an event from the instant that the on-screen drawing of a line reaches a certain point on the screen. The MATLAB graphic system sends coordinate lists of complete lines to the hardware graphic system, which renders the coordinates and flips to new screens all at once (except as needed to transfer rendered information to the display.)
What you will have to do instead is to calculate the point of interception and act upon it appropriately.
Related Question