[1]


Task

Find the point of intersection of two lines in 2D.



The 1st line passes though    (4,0)    and    (6,10) .

The 2nd line passes though    (0,3)    and    (10,7) .




 0 A = 1:B = 2: HOME : VTAB 21: HGR : HCOLOR= 3: FOR L = A TO B: READ X1(L),Y1(L),X2(L),Y2(L): HPLOT X1(L),Y1(L) TO X2(L),Y2(L): NEXT : DATA4,0,6,10,0,3,10,7
 1  GOSUB 5: IF NAN THEN  PRINT "THE LINES DO NOT INTERSECT, THEY ARE EITHER PARALLEL OR CO-INCIDENT."
 2  IF  NOT NAN THEN  PRINT "POINT OF INTERSECTION : "X" "Y
 3  PRINT  CHR$ (13)"HIT ANY KEY TO END PROGRAM": IF  NOT NAN THEN  FOR K = 0 TO 1 STEP 0:C = C = 0: HCOLOR= 3 * C: HPLOT X,Y: FOR I = 1 TO 30:K =  PEEK (49152) > 127: NEXT I,K
 4  GET K$: TEXT : END 
 5  FOR L = A TO B:S$(L) = "NAN": IF X1(L) <  > X2(L) THEN S(L) = (Y1(L) - Y2(L)) / (X1(L) - X2(L)):S$(L) =  STR$ (S(L))
 6  NEXT L:NAN = S$(A) = S$(B): IF NAN THEN  RETURN 
 7  IF S$(A) = "NAN" AND S$(B) <  > "NAN" THEN X = X1(A):Y = (X1(A) - X1(B)) * S(B) + Y1(B): RETURN 
 8  IF S$(B) = "NAN" AND S$(A) <  > "NAN" THEN X = X1(B):Y = (X1(B) - X1(A)) * S(A) + Y1(A): RETURN 
 9 X = (S(A) * X1(A) - S(B) * X1(B) + Y1(B) - Y1(A)) / (S(A) - S(B)):Y = S(B) * (X - X1(B)) + Y1(B): RETURN