Hi everyone, I have been tackling a problem in regards to ray tracing in 2-dimensions and havent been able to find anything helpful to help me start the program I want. My goal is to be able to plot a ray in a confined space that reflects the ray, but each time it hits a wall the ray decays a little until it vanishes eventually. I've been able to plot a ray and a "wall", but making the actual reflecting line is what's troubling me. I have found the point of intersection of 2 lines, and the angle I want the reflection to come out at (supw1). Any help to this problem is greatly appreciated, I essentially want to be able to make the ray "laser" bounce around like the old fashioned DVD logo from back in the day. Attached is the Matlab code I have so far. Thanks in advanced for the help, feel free if you have any questions for clarification.
%line1
x1 = [2 3];y1 = [1 1];%line2
x2 = [2 10];y2 = [0 10];%fit linear polynomial
p1 = polyfit(x1,y1,1);p2 = polyfit(x2,y2,1);% p3 = polyfit(x3,y3,1);
% calculate intersection
x_intersect = fzero(@(x) polyval(p1-p2,x),3);y_intersect = polyval(p1,x_intersect);% function drawLine(point,slope)
% % point - vector [x,y]
% % slope - slope of the line
%
% x = x_intersect;
% y = y_intersect;
% % lengthLine = 5;
% % xLine = x-lengthLine:x+lengthLine;
% yLine = slope*(xLine-x) + y;
% % plot(x,y,'ro')
% plot(xLine,yLine,'b')
% % end
intlines = 1;% if intlines == 1
% plot(
line(x1,y1);hold on;line(x2,y2);plot(x_intersect,y_intersect, 'ro', 'Markersize', 18)rectangle('Position',[1 1 11 11])diff = (atan((y1(2)-y1(1))/(x1(2)-x1(1))) - atan((y2(2)-y2(1))/(x2(2)-x2(1)))) * 180/pi;supw1 = abs(diff / 2);
Best Answer