Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %kod för plan
- u1 = [0 4 -1]
- v1 = [3 -2 1]
- Q1 = [1,2,3]
- u2 = [-5 1 3]
- v2 = [-1 0 1]
- Q2 = [-10,-1,1]
- u3 = [0 1 0]
- v3 = [-1 1 1]
- Q3 = [2,10,0]
- %matriser för vektorer och punkter
- uM = [0 4 -1;-5 1 3;0 1 0]
- vM = [3 -2 1;-1 0 1;-1 1 1]
- QM = [1 2 3;-10 -1 1;2 10 0]
- %plot för fiskens bana
- plot3(X,Y,Z)
- hold on
- plot3(X(1), Y(1), Z(1),'p')
- hold on
- plot3(X(end), Y(end), Z(end),'o')
- hold on
- %kod för plan 3s normalvektor
- n3 = [u3(2)*v3(3)-v3(2)*u3(3) -u3(1)*v3(3)+v3(1)*u3(3) u3(1)*v3(2)-v3(1)*u3(2)]
- %kod för beräkningen av normalvektorn n3s längd
- n3length = sqrt(n3(1)^2+n3(2)^2+n3(3)^2)
- notcaught = 1
- count = 0;
- failed = 0;
- while(notcaught)
- count = count + 1;
- for i = 1:3
- u = uM(i,:)
- v = vM(i,:)
- Q = QM(i,:)
- n = [u(2)*v(3)-v(2)*u(3) -u(1)*v(3)+v(1)*u(3) u(1)*v(2)-v(1)*u(2)]
- nlength = sqrt(n(1)^2+n(2)^2+n(3)^2)
- P = [X(count), Y(count), Z(count)]
- QP = [P(1)-Q(1) P(2)-Q(2) P(3)-Q(3)]
- %projecerar QP på planets normalvektor
- projQPn = (n(1)*QP(1)+n(2)*QP(2)+n(3)*QP(3))/(nlength^2)*n
- %kod för avståndet mellan fisken & planet
- distancelength = sqrt(projQPn(1)^2+projQPn(2)^2+projQPn(3)^2)
- if distancelength <= 0.5
- notcaught = 0;
- timecaught = T(count);
- end
- end
- if count == length(T)
- notcaught = 0;
- failed = 1;
- end
- end
- if failed == 1
- disp('fisken fångades ej av näten')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement