Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- load('fiskbana')
- plot3(X(1),Y(1),Z(1),'o',X(end),Y(end),Z(end),'*',X,Y,Z);
- u = [0,4,-1;-5,1,3;0,1,0];
- v = [3,-2,1;-1,0,1;-1,1,1];
- q = [1,2,3;-10,-1,1;2,10,0];
- P = [X(1), Y(1), Z(1)];
- distvec = [];
- for b = 1:3 %We want to do this for 3 planes
- i = 1; %Denna rackaren viktig!
- normal = crossP(u(b,:),v(b,:));%Calculate the normalvectors for the 3 planes
- while langd(proj(P - q(b,:),normal)) > 0.5 && i < length(T) %The task is to find the length less than 0.5
- P = [X(i), Y(i), Z(i)];
- i = i + 1;
- avs = langd(proj(P - q(b,:),normal)); %Beräkna avstånddet
- distvec = [distvec, avs]; %
- end
- if avs < 0.5 && T(i) < 10
- disp(['Plan ', num2str(b), ' fangade natet efter ', num2str(T(i)), ' sekunder']);
- else
- disp(['Plan ', num2str(b), ' fangade ej fisken innan T = 10 sekunder']);
- end
- end
- function s = skal(a,b)
- s = sum(a.*b);
- end
- function L = langd(a)
- L = sqrt(sum(a.^2));
- end
- function pr = proj(c,d)
- pr = skal(c,d)/(langd(d)^2).*d;
- end
- function cr = crossP(c,d)
- cr = [(c(2)*d(3)-c(3)*d(2));(c(3)*d(1)-c(1)*d(3));(c(1)*d(2)-c(2)*d(1))]';
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement