All pastes #937114 Raw Edit

Stuff

public text v1 · immutable
·published 2008-03-10 21:19 UTC
rendered paste body
hold on
x1 =rand
x2 =rand
x3 =rand
x4 =rand
y1 =rand
y2 =rand
y3 =rand
y4 =rand
syms x
syms y
ec1 = ((y2-y1)/(x2-x1))*(x-x1) - y + y1
ec2 = ((y4-y3)/(x4-x3))*(x-x3) - y + y3
i = min(x1,x2):0.01:max(x1,x2)
j = ((y2-y1)/(x2-x1)).*(i-x1)  + y1
plot(i,j,'r'); 
i = min(x3,x4):0.01:max(x3,x4)
j = (( y4-y3)/(x4-x3)).*(i-x3)  + y3
plot(i,j,'b');
[t,v] = solve(ec1,ec2)

if (double(t)<=max(x1,x2)) & (double(t)<=max(x3,x4)) & (double(t)>=min(x1,x2))  & (double(t)>=min(x3,x4)) 
              plot(double(t),double(v),'*');title('Segmentele se intersecteaza');
             
      else title('Segmentele nu se intersecteaza'); end
hold off