Author Topic: Intersect of 2 lines carried a step further  (Read 9018 times)

0 Members and 1 Guest are viewing this topic.

Offline EricE

  • Forum Regular
  • Posts: 114
Re: Intersect of 2 lines carried a step further
« Reply #15 on: March 16, 2020, 01:11:40 pm »
For this problem I need to know a good value for QB64's Machine Epsilon.

Edited to add:
I just started a new thread on the topic of QB64's Machine Epsilon.
https://www.qb64.org/forum/index.php?topic=2353.0
« Last Edit: March 16, 2020, 01:29:47 pm by EricE »

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
Re: Intersect of 2 lines carried a step further
« Reply #16 on: March 16, 2020, 01:49:38 pm »
Are you guys Erik and Terry talking about lines or line segments?

The code I posted works with line segments. You need to supply the start and end X,Y coordinate pairs for each line segment.
In order to understand recursion, one must first understand recursion.

Offline EricE

  • Forum Regular
  • Posts: 114
Re: Intersect of 2 lines carried a step further
« Reply #17 on: March 16, 2020, 02:05:35 pm »
My code is for the lines containing the segments.
However, adding a simple check will tell if the two segments intersect.

Code: QB64: [Select]
  1. IF (0.0 <= r) AND (r <= 1.0) AND (0.0 <= s) AND (s <= 1.0) THEN
  2.     PRINT "Line segments intersect"
  3.     PRINT "Line segments do not intersect"
  4. <

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #18 on: March 16, 2020, 02:13:52 pm »
The code I posted works with line segments. You need to supply the start and end X,Y coordinate pairs for each line segment.

Yeah I was looking over your code Terry, you are even checking if points are co-linear but 3 at a time and in a weird way ie rotation clockwise or counter? I don't see line segments turning one way or another. Otherwise I would try to test your routines in the tester code.

Quote
You need to supply the start and end X,Y coordinate pairs for each line segment.
Just what the tester code sets up unless it makes a difference which is first and which is second. Still working through the code... maybe the orientation stuff is all internal and I just need a pointType to plug the numbers there.
ObjIntersect only returns true or false for intersect and/or for overlap?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #19 on: March 16, 2020, 02:17:01 pm »
My code is for the lines containing the segments.
However, adding a simple check will tell if the two segments intersect.

Code: QB64: [Select]
  1. IF (0.0 <= r) AND (r <= 1.0) AND (0.0 <= s) AND (s <= 1.0) THEN
  2.     PRINT "Line segments intersect"
  3.     PRINT "Line segments do not intersect"
  4. <

Your code only works if D <> 0
Quote
Code: QB64: [Select]
  1. ' Compute determinant
  2. DetV = -v1(1) * v2(2) + v2(1) * v1(2)
  3. ' DetV must not be zero

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
Re: Intersect of 2 lines carried a step further
« Reply #20 on: March 16, 2020, 02:45:07 pm »
Note the source cited in my code. I don't claim to have written that code myself, I converted it from the source cited. The clockwise/counter-clockwise thing has me a bit confused as well.
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #21 on: March 16, 2020, 06:50:33 pm »
I have modified the twoSegmentsIntersect FUNCTION or SUB tester code. It was missing an important case of 2 segments lying on the same vertical line. Now the SUB or FUNCTION should ID either the Intersect Point or the segment Overlap boundary 2 end points (which could be the same if they only overlap at one point).

Code: QB64: [Select]
  1. _TITLE "Segments Intersect mod tester" 'b+ 2020-03-16
  2. ' Just worked Rosetta Code for Line Intersect Line
  3. ' but what if we want to know if two line segments intersect?
  4. '2020-03-14 "Two Line Segments Intersect" 'b+ 2020-03-14  start
  5. '2020-03-15 rework this code so we identify points all on same line and
  6. ' if there is overlap of line segments say the two x endpoints of the segments
  7. ' otherwise, if there is an intersect of 2 line segments say the point x, y.
  8. ' Return 0 no intersect or overlap
  9. ' Return 1 if intersect and ix, iy point of intersect
  10. ' Return -1 if segments are on same and there is overlap: ix = overlap start x, iy overlap end x
  11.  
  12. '2020-03-16 "Segments Intersect mod tester"
  13. 'mod tester for 2 segments of vertical line and found I need to add more parameters to
  14. ' FUNCTION twoLineSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  15. ' mod that name and parameters to:
  16. ' FUNCTION twoSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, i1x, i1y, i2x, i2y)
  17.  
  18. CONST xmax = 1200, ymax = 700
  19. SCREEN _NEWIMAGE(xmax, ymax, 32)
  20. _DELAY .25
  21. DIM ax1 AS INTEGER, ax2 AS INTEGER, ay1 AS INTEGER, ay2 AS INTEGER
  22. DIM bx1 AS INTEGER, bx2 AS INTEGER, by1 AS INTEGER, by2 AS INTEGER
  23.     restartA:
  24.     CLS
  25.     IF RND < .5 THEN 'throw in some vertical lines
  26.         LOCATE 3, 80: PRINT "Red Points are vertical."
  27.         ax1 = (xmax - 20) * RND + 10: ay1 = (ymax - 60) * RND + 50
  28.         ax2 = ax1: ay2 = (ymax - 60) * RND + 50
  29.     ELSE
  30.         LOCATE 3, 80: PRINT "Red Points are Random."
  31.         ax1 = (xmax - 20) * RND + 10: ay1 = (ymax - 60) * RND + 50
  32.         ax2 = (xmax - 20) * RND + 10: ay2 = (ymax - 60) * RND + 50
  33.     END IF
  34.     IF _HYPOT(ax1 - ax2, ay1 - ay2) < 50 THEN GOTO restartA
  35.  
  36.     IF RND < .5 THEN 'get some points on same line
  37.         LOCATE 3, 80: PRINT "Blue Points are on same line as Red."
  38.         slopeYintersect ax1, ay1, ax2, ay2, slope1, Yintercept1
  39.         bx1 = (xmax - 20) * RND + 10: by1 = bx1 * slope1 + Yintercept1
  40.         bx2 = (xmax - 20) * RND + 10: by2 = bx2 * slope1 + Yintercept1
  41.     ELSE
  42.         IF RND < .4 THEN 'throw in some verticals, we already have a doing verticals
  43.             LOCATE 3, 80: PRINT SPACE$(50)
  44.             LOCATE 3, 80: PRINT "All points vertical."
  45.             ax1 = (xmax - 20) * RND + 10: ax2 = ax1: bx1 = ax1: bx2 = ax1
  46.             ay1 = 50 + RND * 50: ay2 = ay1 + 50 + RND * 50
  47.             by1 = ay1 + 25 + RND * 50: by2 = by1 + 50 + (RND * ymax - 60 - by1)
  48.             by1 = (ymax - 60) * RND + 50: bx2 = bx1: by2 = (ymax - 60) * RND + 50
  49.         ELSE
  50.             LOCATE 4, 80: PRINT "Blue Points are Random."
  51.             bx1 = (xmax - 20) * RND + 10: by1 = (ymax - 60) * RND + 50
  52.             bx2 = (xmax - 20) * RND + 10: by2 = (ymax - 60) * RND + 50
  53.         END IF
  54.     END IF
  55.     IF bx1 < 10 OR bx1 > xmax - 10 THEN GOTO restartA
  56.     IF bx2 < 10 OR bx2 > xmax - 10 THEN GOTO restartA
  57.     IF by1 < 50 OR by1 > ymax - 10 THEN GOTO restartA
  58.     IF by2 < 50 OR by2 > ymax - 10 THEN GOTO restartA
  59.     IF _HYPOT(bx1 - bx2, by1 - by2) < 30 THEN GOTO restartA
  60.  
  61.     LINE (ax1, ay1)-(ax2, ay2), &HFFFF0000
  62.     CIRCLE (ax1, ay1), 4, &HFFFF0000
  63.     CIRCLE (ax2, ay2), 4, &HFFFF0000
  64.  
  65.     LINE (bx1, by1)-(bx2, by2), &HFF0000FF
  66.     CIRCLE (bx1, by1), 4, &HFF0000FF
  67.     CIRCLE (bx2, by2), 4, &HFF0000FF
  68.  
  69.     LOCATE 1, 1
  70.     PRINT "Segments ("; ts$(ax1); ", "; ts$(ay1); ") ("; ts$(ax2); ", ";_
  71.      ts$(ay2); ") and ("; ts$(bx1); ", "; ts$(by1); ") ("; ts$(bx2); ", "; ts$(by2); ")"
  72.  
  73.     '                    Plug in your 2 Segment Intersect SUB or FUNCTION Here
  74.     '                 and interpret reults: yellow circle around intersect point
  75.     '                and an alpha shaded box where two co-linear segments overlap
  76.     '=====================================================================================================
  77.     'intersect = twoSegmentsIntersect%(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, i1x, i1y, i2x, i2y)
  78.     'IF intersect = -1 THEN 'segments overlap on same line
  79.     '    PRINT " Segments overlap between min x at "; ts$(ix); " and max x at "; ts$(iy) '< not a "y" here
  80.     '    LINE (i1x, i1y)-(i2x, i2y), &HFFFFFFFF
  81.     'ELSEIF intersect = 1 THEN 'segments intersect at one point
  82.     '    PRINT " Segments intersect at ("; ts$(ix); ", "; ts$(iy); ")."
  83.     '    CIRCLE (ix, iy), 3, &HFFFFFFFF
  84.     'ELSEIF intersect = 0 THEN 'segments do not intersect nor overlap
  85.     '    PRINT " Segments do not Intersect or Overlap."
  86.     'END IF
  87.     '=====================================================================================================
  88.  
  89.     INPUT "Press enter for another demo, any + enter to quit...", again$
  90.     CLS
  91. LOOP UNTIL LEN(again$)
  92.  
  93. 'Slope and Y-intersect for non vertical lines,
  94. ' if x1 = x2 the line is vertical don't call this sub
  95. ' because slope calculation would cause division by 0 error.
  96. SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) 'check x1 <> x2 first!
  97.     slope = (Y2 - Y1) / (X2 - X1): Yintercept = slope * (0 - X1) + Y1
  98.  
  99. FUNCTION ts$ (n)
  100.     ts$ = _TRIM$(STR$(INT(100 * n) / 100))
  101. ' ======================================== end tester code functions ======================================
  102.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #22 on: March 16, 2020, 09:57:49 pm »
OK I think I got it, running without error over 100 tests:
Code: QB64: [Select]
  1. _TITLE "Segments Intersect revised 2020-03-16:  White Circles are Intersects White Lines are Overlaps" 'b+ 2020-03-16
  2. ' Just worked Rosetta Code for Line Intersect Line
  3. ' but what if we want to know if two line segments intersect?
  4. '2020-03-14 "Two Line Segments Intersect" 'b+ 2020-03-14  start
  5. '2020-03-15 rework this code so we identify points all on same line and
  6. ' if there is overlap of line segments say the two x endpoints of the segments
  7. ' otherwise, if there is an intersect of 2 line segments say the point x, y.
  8. ' Return 0 no intersect or overlap
  9. ' Return 1 if intersect and ix, iy point of intersect
  10. ' Return -1 if segments are on same and there is overlap: ix = overlap start x, iy overlap end x
  11.  
  12. '2020-03-16 "Segments Intersect mod tester"  >>> just post testing code
  13. 'mod tester for 2 segments of vertical line and found I need to add more parameters to
  14. ' FUNCTION twoLineSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  15. ' mod that name and parameters to:
  16. ' FUNCTION twoSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1, ix2, iy2)
  17.  
  18. '2020-03-16 Segments Intersect revised 2020-03-16
  19. ' OK now get the new FUNCTION working
  20. ' ah! I had to tighten down D from >.2 to >.05 but loosen y-axis intersect
  21.  
  22. CONST xmax = 1200, ymax = 700
  23. SCREEN _NEWIMAGE(xmax, ymax, 32)
  24. _DELAY .25
  25. DIM ax1 AS INTEGER, ax2 AS INTEGER, ay1 AS INTEGER, ay2 AS INTEGER
  26. DIM bx1 AS INTEGER, bx2 AS INTEGER, by1 AS INTEGER, by2 AS INTEGER
  27.     restartA:
  28.     CLS
  29.     IF RND < .3 THEN 'throw in some vertical lines
  30.         LOCATE 3, 80: PRINT "Red Points are vertical."
  31.         ax1 = (xmax - 20) * RND + 10: ay1 = (ymax - 60) * RND + 50
  32.         ax2 = ax1: ay2 = (ymax - 60) * RND + 50
  33.     ELSE
  34.         LOCATE 3, 80: PRINT "Red Points are Random."
  35.         ax1 = (xmax - 20) * RND + 10: ay1 = (ymax - 60) * RND + 50
  36.         ax2 = (xmax - 20) * RND + 10: ay2 = (ymax - 60) * RND + 50
  37.     END IF
  38.     IF _HYPOT(ax1 - ax2, ay1 - ay2) < 50 THEN GOTO restartA
  39.  
  40.     IF RND < .6 THEN 'get some points on same line
  41.         LOCATE 3, 80: PRINT "Blue Points are on same line as Red."
  42.         slopeYintersect ax1, ay1, ax2, ay2, slope1, Yintercept1
  43.         bx1 = (xmax - 20) * RND + 10: by1 = bx1 * slope1 + Yintercept1
  44.         bx2 = (xmax - 20) * RND + 10: by2 = bx2 * slope1 + Yintercept1
  45.     ELSE
  46.         IF RND < .4 THEN 'throw in some verticals, we already have a doing verticals
  47.             LOCATE 3, 80: PRINT SPACE$(50)
  48.             LOCATE 3, 80: PRINT "All points vertical."
  49.             ax1 = (xmax - 20) * RND + 10: ax2 = ax1: bx1 = ax1: bx2 = ax1
  50.             ay1 = 50 + RND * 50: ay2 = ay1 + 50 + RND * 50
  51.             by1 = ay1 + 25 + RND * 50: by2 = by1 + 50 + (RND * ymax - 60 - by1)
  52.             by1 = (ymax - 60) * RND + 50: bx2 = bx1: by2 = (ymax - 60) * RND + 50
  53.         ELSE
  54.             LOCATE 4, 80: PRINT "Blue Points are Random."
  55.             bx1 = (xmax - 20) * RND + 10: by1 = (ymax - 60) * RND + 50
  56.             bx2 = (xmax - 20) * RND + 10: by2 = (ymax - 60) * RND + 50
  57.         END IF
  58.     END IF
  59.     IF bx1 < 10 OR bx1 > xmax - 10 THEN GOTO restartA
  60.     IF bx2 < 10 OR bx2 > xmax - 10 THEN GOTO restartA
  61.     IF by1 < 50 OR by1 > ymax - 10 THEN GOTO restartA
  62.     IF by2 < 50 OR by2 > ymax - 10 THEN GOTO restartA
  63.     IF _HYPOT(bx1 - bx2, by1 - by2) < 30 THEN GOTO restartA
  64.  
  65.     LINE (ax1, ay1)-(ax2, ay2), &HFFFF0000
  66.     CIRCLE (ax1, ay1), 4, &HFFFF0000
  67.     CIRCLE (ax2, ay2), 4, &HFFFF0000
  68.  
  69.     LINE (bx1, by1)-(bx2, by2), &HFF0000FF
  70.     CIRCLE (bx1, by1), 4, &HFF0000FF
  71.     CIRCLE (bx2, by2), 4, &HFF0000FF
  72.  
  73.     LOCATE 1, 1
  74.     PRINT "Segments ("; ts$(ax1); ", "; ts$(ay1); ") ("; ts$(ax2); ", ";_
  75.      ts$(ay2); ") and ("; ts$(bx1); ", "; ts$(by1); ") ("; ts$(bx2); ", "; ts$(by2); ")"
  76.  
  77.     '                    Plug in your 2 Segment Intersect SUB or FUNCTION Here
  78.     '                 and interpret reults: yellow circle around intersect point
  79.     '                and an alpha shaded box where two co-linear segments overlap
  80.     '=====================================================================================================
  81.     intersect = twoSegmentsIntersect%(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1, ix2, iy2)
  82.     IF intersect = -1 THEN 'segments overlap on same line
  83.         PRINT " Segments overlap between: ("; ts$(ix1); ", "; ts$(iy1); ") and ("; ts$(ix2); ", "; ts$(iy2); ")"
  84.         LINE (ix1, iy1)-(ix2, iy2), &HFFFFFFFF
  85.     ELSEIF intersect = 1 THEN 'segments intersect at one point
  86.         PRINT " Segments intersect: ("; ts$(ix1); ", "; ts$(iy1); ")"
  87.         CIRCLE (ix1, iy1), 3, &HFFFFFFFF
  88.     ELSEIF intersect = 0 THEN 'segments do not intersect nor overlap
  89.         PRINT " Segments do not Intersect or Overlap."
  90.     END IF
  91.     '=====================================================================================================
  92.  
  93.     INPUT "Press enter for another demo, any + enter to quit...", again$
  94.     CLS
  95. LOOP UNTIL LEN(again$)
  96.  
  97. 'Slope and Y-intersect for non vertical lines,
  98. ' if x1 = x2 the line is vertical don't call this sub
  99. ' because slope calculation would cause division by 0 error.
  100. SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) 'check x1 <> x2 first!
  101.     slope = (Y2 - Y1) / (X2 - X1): Yintercept = slope * (0 - X1) + Y1
  102.  
  103. FUNCTION ts$ (n)
  104.     ts$ = _TRIM$(STR$(INT(100 * n) / 100))
  105. ' ======================================== end tester code functions ======================================
  106.  
  107.  
  108. 'This function needs: FUNCTION lineIntersectLine% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  109. ' which in turn needs: SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) 'check x1 <> x2 first!
  110. FUNCTION twoSegmentsIntersect% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1, ix2, iy2)
  111.     intersect = lineIntersectLine%(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  112.     IF ax1 < ax2 THEN aMinX = ax1: aMaxX = ax2 ELSE aMinX = ax2: aMaxX = ax1
  113.     IF ay1 < ay2 THEN aMinY = ay1: aMaxY = ay2 ELSE aMinY = ay2: aMaxY = ay1
  114.     IF bx1 < bx2 THEN bMinX = bx1: bMaxX = bx2 ELSE bMinX = bx2: bMaxX = bx1
  115.     IF by1 < by2 THEN bMinY = by1: bMaxY = by2 ELSE bMinY = by2: bMaxY = by1
  116.     IF intersect = 0 THEN 'no  intersect
  117.         twoSegmentsIntersect% = 0
  118.     ELSEIF intersect = 1 THEN 'segments intersect at one point
  119.         IF ax1 = ax2 THEN 'is iy between
  120.             IF iy < aMinY OR iy > aMaxY OR ix < bMinX OR ix > bMaxX THEN
  121.                 twoSegmentsIntersect% = 0
  122.             ELSE
  123.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  124.             END IF
  125.         ELSEIF bx1 = bx2 THEN
  126.             IF iy < bMinY OR iy > bMaxY OR ix < aMinX OR ix > aMaxX THEN
  127.                 twoSegmentsIntersect% = 0
  128.             ELSE
  129.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  130.             END IF
  131.         ELSE
  132.             IF (aMinX <= ix AND ix <= aMaxX) AND (bMinX <= ix AND ix <= bMaxX) THEN
  133.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  134.             ELSE
  135.                 twoSegmentsIntersect% = 0
  136.             END IF
  137.         END IF
  138.     ELSEIF intersect = -1 THEN 'segments are on same line get over lap section
  139.         'first check if both are on vertical line
  140.         IF ax1 = ax2 THEN 'and we know both are same line  we have two vertical segemnts, do they over lap?
  141.             ix1 = ax1: ix2 = ax1
  142.             IF aMinY < bMinY THEN
  143.                 IF aMaxY < bMinY THEN
  144.                     twoSegmentsIntersect% = 0
  145.                 ELSE
  146.                     twoSegmentsIntersect% = -1: iy1 = bMinY
  147.                     IF aMaxY > bMaxY THEN
  148.                         iy2 = bMaxY
  149.                     ELSE
  150.                         iy2 = aMaxY
  151.                     END IF
  152.                 END IF
  153.             ELSE 'bMinY <= aMinY
  154.                 IF bMaxY < aMinY THEN
  155.                     twoSegmentsIntersect% = 0
  156.                 ELSE
  157.                     twoSegmentsIntersect% = -1: iy1 = aMinY
  158.                     IF bMaxY > aMaxY THEN
  159.                         iy2 = aMaxY
  160.                     ELSE
  161.                         iy2 = bMaxY
  162.                     END IF
  163.                 END IF
  164.             END IF
  165.         ELSE 'the same line is not vertical
  166.             IF aMinX < bMinX THEN
  167.                 IF aMaxX < bMinX THEN
  168.                     twoSegmentsIntersect% = 0
  169.                 ELSE
  170.                     twoSegmentsIntersect% = -1: ix1 = bMinX
  171.                     IF bx1 = bMinX THEN iy1 = by1 ELSE iy1 = by2
  172.                     IF aMaxX > bMaxX THEN
  173.                         ix2 = bMaxX
  174.                         IF bx1 = bMaxX THEN iy2 = by1 ELSE iy2 = by2
  175.                     ELSE
  176.                         ix2 = aMaxX
  177.                         IF ax1 = aMaxX THEN iy2 = ay1 ELSE iy2 = ay2
  178.                     END IF
  179.                 END IF
  180.             ELSE 'aMinX >= bMinX
  181.                 IF aMinX > bMaxX THEN
  182.                     twoSegmentsIntersect% = 0
  183.                 ELSE
  184.                     twoSegmentsIntersect% = -1: ix1 = aMinX
  185.                     IF ax1 = aMinX THEN iy1 = ay1 ELSE iy1 = ay2
  186.                     IF bMaxX > aMaxX THEN
  187.                         ix2 = aMaxX
  188.                         IF ax1 = aMaxX THEN iy2 = ay1 ELSE iy2 = ay2
  189.                     ELSE
  190.                         ix2 = bMaxX
  191.                         IF bx1 = bMaxX THEN iy2 = by1 ELSE iy2 = by2
  192.                     END IF
  193.                 END IF
  194.             END IF
  195.         END IF
  196.     END IF
  197.  
  198. ' this function needs: SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept)
  199. FUNCTION lineIntersectLine% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  200.     IF ax1 = ax2 THEN 'line a is vertical
  201.         IF bx1 = bx2 THEN ' b is vertical
  202.             IF ax1 = bx1 THEN lineIntersectLine% = -1 ' if x's are same it is same vertical line
  203.             EXIT FUNCTION '
  204.         ELSE
  205.             ix = ax1
  206.             slopeYintersect bx1, by1, bx2, by2, m2, y02
  207.             iy = m2 * ix + y02
  208.             lineIntersectLine% = 1 'signal a point was found
  209.             EXIT FUNCTION
  210.         END IF
  211.     ELSE
  212.         slopeYintersect ax1, ay1, ax2, ay2, m1, y01 ' -m = a, 1 = b, y0 = c  std form
  213.     END IF
  214.     IF bx1 = bx2 THEN 'b is vertical
  215.         ix = bx1: iy = m1 * ix + y01: lineIntersectLine% = 1 'signal a point was found
  216.         EXIT FUNCTION
  217.     ELSE
  218.         slopeYintersect bx1, by1, bx2, by2, m2, y02 ' -m = a, 1 = b, y0 = c  std form
  219.     END IF
  220.     d = -m1 - -m2 ' if = 0 then parallel or equal because slopes are same
  221.     IF ABS(d) > .05 THEN 'otherwise about 0 <<< tighten down from .2 to .05
  222.         ix = (y01 - y02) / d: iy = (-m1 * y02 - -m2 * y01) / d
  223.         lineIntersectLine% = 1 'signal one intersect point was found
  224.     ELSE 'same line or parallel? if y0 (y-axis interssect) are same they are the same
  225.         IF ABS(y01 - y02) < 15 THEN lineIntersectLine% = -1 'signal same line!  <<< loosen more! 5 to 15
  226.     END IF
  227.  

Best answer so far, if anyone can cut down the size of twoSegmentIntersect%() Function...?


2020-03-18 Update: I have tested the twoSegmentIntersect%() Function in "Two Triangles Overlap" see below and found the Overlap signal was coming up with allot of false positives, so there is plenty of room for improvement yet remaining.
« Last Edit: March 18, 2020, 12:37:50 am by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Intersect of 2 lines carried a step further
« Reply #23 on: March 17, 2020, 06:30:51 pm »
I worked something useful out on paper - if I can just get a darn second to sit and crystallize it I'll meet you at the end bplus!
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Intersect of 2 lines carried a step further
« Reply #24 on: March 17, 2020, 08:31:04 pm »
I just heard "her" car pull in so I gotta go but here's what I have buddy. Hope it adds to something!

Drag line with mouse 1

Rotate with mouse wheel

All cases covered except parallel, which is easy

Code: QB64: [Select]
  1.  
  2. TYPE Vector
  3.     x AS DOUBLE
  4.     y AS DOUBLE
  5.  
  6. TYPE LineSegment
  7.     b AS Vector
  8.     alpha1 AS DOUBLE
  9.     alpha2 AS DOUBLE
  10.     ang AS DOUBLE
  11.     t AS Vector
  12.     p1 AS Vector
  13.     p2 AS Vector
  14.  
  15. DIM SHARED Segments(2) AS LineSegment
  16.  
  17. Segments(1).b.x = 0
  18. Segments(1).b.y = 0
  19. Segments(1).alpha1 = -150
  20. Segments(1).alpha2 = 150
  21. Segments(1).ang = 0
  22. CALL CalcLine(1)
  23.  
  24. Segments(2).b.x = 0
  25. Segments(2).b.y = 50
  26. Segments(2).alpha1 = -150
  27. Segments(2).alpha2 = 150
  28. Segments(2).ang = ATN(1)
  29. CALL CalcLine(2)
  30.  
  31.  
  32.         x = _MOUSEX
  33.         y = _MOUSEY
  34.         IF ((x > 0) AND (x < _WIDTH) AND (y > 0) AND (y < _HEIGHT)) THEN
  35.             IF _MOUSEBUTTON(1) THEN
  36.                 x = _MOUSEX
  37.                 y = _MOUSEY
  38.                 Segments(1).b.x = (x - _WIDTH / 2)
  39.                 Segments(1).b.y = (-y + _HEIGHT / 2)
  40.                 CALL CalcLine(1)
  41.             END IF
  42.             IF _MOUSEWHEEL > 0 THEN
  43.                 Segments(1).ang = Segments(1).ang + ATN(1) / 10
  44.                 CALL CalcLine(1)
  45.             END IF
  46.             IF _MOUSEWHEEL < 0 THEN
  47.                 Segments(1).ang = Segments(1).ang - ATN(1) / 10
  48.                 CALL CalcLine(1)
  49.             END IF
  50.         END IF
  51.     LOOP
  52.  
  53.     CLS
  54.     CALL cline(Segments(1).p1.x, Segments(1).p1.y, Segments(1).p2.x, Segments(1).p2.y, 15)
  55.     CALL cline(Segments(2).p1.x, Segments(2).p1.y, Segments(2).p2.x, Segments(2).p2.y, 14)
  56.  
  57.     ''' Intersection calculation
  58.     DIM db AS Vector
  59.     db.x = Segments(2).b.x - Segments(1).b.x
  60.     db.y = Segments(2).b.y - Segments(1).b.y
  61.     qj = DotProduct(db, Segments(1).t)
  62.     ql = DotProduct(db, Segments(2).t)
  63.     p = DotProduct(Segments(1).t, Segments(2).t)
  64.     pp = p * p
  65.     IF (pp < 1) THEN
  66.         alphaj = (qj - p * ql) / (1 - pp)
  67.         alphal = (p * qj - ql) / (1 - pp) ' This is actually redundant (along with anything depending on it.)
  68.         IF ((alphaj > Segments(1).alpha1) AND (alphaj < Segments(1).alpha2)) THEN
  69.             IF ((alphal > Segments(2).alpha1) AND (alphal < Segments(2).alpha2)) THEN
  70.                 CALL ccircle(Segments(1).b.x + alphaj * Segments(1).t.x, Segments(1).b.y + alphaj * Segments(1).t.y, 5, 15)
  71.                 CALL ccircle(Segments(2).b.x + alphal * Segments(2).t.x, Segments(2).b.y + alphal * Segments(2).t.y, 5, 15)
  72.             END IF
  73.         END IF
  74.     ELSE
  75.         ' Parallel case.
  76.     END IF
  77.     '''
  78.  
  79.     _DISPLAY
  80.     _LIMIT 60
  81.  
  82.  
  83. SUB CalcLine (i AS INTEGER)
  84.     Segments(i).t.x = COS(Segments(i).ang)
  85.     Segments(i).t.y = SIN(Segments(i).ang)
  86.     Segments(i).p1.x = Segments(i).b.x + Segments(i).alpha1 * Segments(i).t.x
  87.     Segments(i).p1.y = Segments(i).b.y + Segments(i).alpha1 * Segments(i).t.y
  88.     Segments(i).p2.x = Segments(i).b.x + Segments(i).alpha2 * Segments(i).t.x
  89.     Segments(i).p2.y = Segments(i).b.y + Segments(i).alpha2 * Segments(i).t.y
  90.  
  91. FUNCTION DotProduct (a AS Vector, b AS Vector)
  92.     DotProduct = a.x * b.x + a.y * b.y
  93.  
  94. SUB cline (x1 AS DOUBLE, y1 AS DOUBLE, x2 AS DOUBLE, y2 AS DOUBLE, col AS _UNSIGNED LONG)
  95.     LINE (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2)-(_WIDTH / 2 + x2, -y2 + _HEIGHT / 2), col
  96.  
  97. SUB ccircle (x1 AS DOUBLE, y1 AS DOUBLE, rad AS DOUBLE, col AS _UNSIGNED LONG)
  98.     CIRCLE (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2), rad, col
  99.  
  100. SUB cpset (x1 AS DOUBLE, y1 AS DOUBLE, col AS _UNSIGNED LONG)
  101.     PSET (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2), col
  102.  
  103. SUB cpaint (x1 AS DOUBLE, y1 AS DOUBLE, col1 AS _UNSIGNED LONG, col2 AS _UNSIGNED LONG)
  104.     PAINT (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2), col1, col2
  105.  
  106. SUB cprintstring (y AS DOUBLE, a AS STRING)
  107.     _PRINTSTRING (_WIDTH / 2 - (LEN(a) * 8) / 2, -y + _HEIGHT / 2), a
  108.  
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #25 on: March 17, 2020, 10:41:21 pm »
Dang I had intersections done in the first OP, that's easy. Find when and where they overlap (on the same line) too, draw that line segment. That was like 75% of my subroutine and 90% of my time. That's what TempodiBasic pointed out.

Dang but those lines looked sharp and clean, oh it's the angle.

Here is the challenging case (that I have solved) determine if 2 line segments are sitting on the same line or do they lay on different lines that intersect, if they overlap, say the 2 endpoints that contain the overlap, if they intersect say the intersect point, or say they neither intersect nor overlap.
no overlap.PNG
* no overlap.PNG (Filesize: 4.72 KB, Dimensions: 642x509, Views: 204)
« Last Edit: March 17, 2020, 11:00:03 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Intersect of 2 lines carried a step further
« Reply #26 on: March 17, 2020, 11:31:44 pm »
You got it man - I swear next time I sit down I'll finish my math up there - it'll stay tight, promise.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #27 on: March 18, 2020, 12:32:28 am »
Oh rats and nutz and worse@!

Turns out all I really needed was intersect, at least with completely random triangles. It is rare occasion two line segments actually do line up on exact line. Here is basically what I was going after, and intersect handles it nicely:

Code: QB64: [Select]
  1. _TITLE "Two Triangles Overlap is Outlined in White dots" 'b+ 2020-03-18
  2. ' Just worked Rosetta Code for Line Intersect Line
  3. ' but what if we want to know if two line segments intersect?
  4. '2020-03-14 "Two Line Segments Intersect" 'b+ 2020-03-14  start
  5. '2020-03-15 rework this code so we identify points all on same line and
  6. ' if there is overlap of line segments say the two x endpoints of the segments
  7. ' otherwise, if there is an intersect of 2 line segments say the point x, y.
  8. ' Return 0 no intersect or overlap
  9. ' Return 1 if intersect and ix, iy point of intersect
  10. ' Return -1 if segments are on same and there is overlap: ix = overlap start x, iy overlap end x
  11.  
  12. '2020-03-16 "Segments Intersect mod tester"  >>> just post testing code
  13. 'mod tester for 2 segments of vertical line and found I need to add more parameters to
  14. ' FUNCTION twoLineSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  15. ' mod that name and parameters to:
  16. ' FUNCTION twoSegmentsIntersect%  (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1, ix2, iy2)
  17.  
  18. '2020-03-16 Segments Intersect revised 2020-03-16
  19. ' OK now get the new FUNCTION working
  20. ' ah! I had to tighten down D from >.2 to >.05 but loosen y-axis intersect
  21.  
  22. '2020-03-18 apply routines to two triangles
  23. ' modified FUNCTION twoSegmentsIntersect% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1)
  24. ' to do only intersect. This code proved, Segments Intersect revised 2020-03-16, was faulty.
  25.  
  26. CONST xmax = 800, ymax = 600
  27. SCREEN _NEWIMAGE(xmax, ymax, 32)
  28. _DELAY .25
  29. DIM ax1 AS INTEGER, ax2 AS INTEGER, ay1 AS INTEGER, ay2 AS INTEGER, ax3 AS INTEGER, ay3 AS INTEGER
  30. DIM bx1 AS INTEGER, bx2 AS INTEGER, by1 AS INTEGER, by2 AS INTEGER, bx3 AS INTEGER, by3 AS INTEGER
  31.     ax1 = (xmax - 20) * RND + 10: ay1 = (ymax - 20) * RND + 10
  32.     ax2 = (xmax - 20) * RND + 10: ay2 = (ymax - 20) * RND + 10
  33.     ax3 = (xmax - 20) * RND + 10: ay3 = (ymax - 20) * RND + 10
  34.     bx1 = (xmax - 20) * RND + 10: by1 = (ymax - 20) * RND + 10
  35.     bx2 = (xmax - 20) * RND + 10: by2 = (ymax - 20) * RND + 10
  36.     bx3 = (xmax - 20) * RND + 10: by3 = (ymax - 20) * RND + 10
  37.     'tri a
  38.     LINE (ax1, ay1)-(ax2, ay2), &HFFFF0000
  39.     LINE (ax2, ay2)-(ax3, ay3), &HFFFF0000
  40.     LINE (ax3, ay3)-(ax1, ay1), &HFFFF0000
  41.     'tri b
  42.     LINE (bx1, by1)-(bx2, by2), &HFF0000FF
  43.     LINE (bx2, by2)-(bx3, by3), &HFF0000FF
  44.     LINE (bx3, by3)-(bx1, by1), &HFF0000FF
  45.  
  46.     dista2a3 = _HYPOT(ax2 - ax3, ay2 - ay3)
  47.     adx = (ax3 - ax2) / dista2a3: ady = (ay3 - ay2) / dista2a3
  48.     distb2b3 = _HYPOT(bx2 - bx3, by2 - by3)
  49.     bdx = (bx3 - bx2) / distb2b3: bdy = (by3 - by2) / distb2b3
  50.  
  51.     FOR i = 0 TO dista2a3
  52.         x1 = ax2 + adx * i: y1 = ay2 + ady * i
  53.         sect = twoSegmentsIntersect%(ax1, ay1, x1, y1, bx1, by1, bx2, by2, ix1, iy1)
  54.         IF sect THEN PSET (ix1, iy1)
  55.         sect = twoSegmentsIntersect%(ax1, ay1, x1, y1, bx3, by3, bx2, by2, ix1, iy1)
  56.         IF sect THEN PSET (ix1, iy1)
  57.         sect = twoSegmentsIntersect%(ax1, ay1, x1, y1, bx1, by1, bx3, by3, ix1, iy1)
  58.         IF sect = 1 THEN PSET (ix1, iy1)
  59.     NEXT
  60.  
  61.     FOR i = 0 TO distb2b3
  62.         x1 = bx2 + bdx * i: y1 = by2 + bdy * i
  63.         sect = twoSegmentsIntersect%(bx1, by1, x1, y1, ax1, ay1, ax2, ay2, ix1, iy1)
  64.         IF sect = 1 THEN PSET (ix1, iy1)
  65.         sect = twoSegmentsIntersect%(bx1, by1, x1, y1, ax3, ay3, ax2, ay2, ix1, iy1)
  66.         IF sect THEN PSET (ix1, iy1)
  67.         sect = twoSegmentsIntersect%(bx1, by1, x1, y1, ax1, ay1, ax3, ay3, ix1, iy1)
  68.         IF sect = 1 THEN PSET (ix1, iy1)
  69.     NEXT
  70.  
  71.     INPUT "Press enter for another demo, any + enter to quit...", again$
  72.     CLS
  73. LOOP UNTIL LEN(again$)
  74.  
  75. 'Slope and Y-intersect for non vertical lines,
  76. ' if x1 = x2 the line is vertical don't call this sub
  77. ' because slope calculation would cause division by 0 error.
  78. SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) 'check x1 <> x2 first!
  79.     slope = (Y2 - Y1) / (X2 - X1): Yintercept = slope * (0 - X1) + Y1
  80.  
  81. ' ======================================== end tester code functions ======================================
  82.  
  83. 'This function needs: FUNCTION lineIntersectLine% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  84. ' which in turn needs: SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept) 'check x1 <> x2 first!
  85. FUNCTION twoSegmentsIntersect% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix1, iy1)
  86.     intersect = lineIntersectLine%(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  87.     IF ax1 < ax2 THEN aMinX = ax1: aMaxX = ax2 ELSE aMinX = ax2: aMaxX = ax1
  88.     IF ay1 < ay2 THEN aMinY = ay1: aMaxY = ay2 ELSE aMinY = ay2: aMaxY = ay1
  89.     IF bx1 < bx2 THEN bMinX = bx1: bMaxX = bx2 ELSE bMinX = bx2: bMaxX = bx1
  90.     IF by1 < by2 THEN bMinY = by1: bMaxY = by2 ELSE bMinY = by2: bMaxY = by1
  91.     IF intersect = 0 THEN 'no  intersect
  92.         twoSegmentsIntersect% = 0
  93.     ELSEIF intersect = 1 THEN 'segments intersect at one point
  94.         IF ax1 = ax2 THEN 'is iy between
  95.             IF iy < aMinY OR iy > aMaxY OR ix < bMinX OR ix > bMaxX THEN
  96.                 twoSegmentsIntersect% = 0
  97.             ELSE
  98.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  99.             END IF
  100.         ELSEIF bx1 = bx2 THEN
  101.             IF iy < bMinY OR iy > bMaxY OR ix < aMinX OR ix > aMaxX THEN
  102.                 twoSegmentsIntersect% = 0
  103.             ELSE
  104.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  105.             END IF
  106.         ELSE
  107.             IF (aMinX <= ix AND ix <= aMaxX) AND (bMinX <= ix AND ix <= bMaxX) THEN
  108.                 ix1 = ix: iy1 = iy: twoSegmentsIntersect% = 1
  109.             END IF
  110.         END IF
  111.     END IF
  112.  
  113. ' this function needs: SUB slopeYintersect (X1, Y1, X2, Y2, slope, Yintercept)
  114. FUNCTION lineIntersectLine% (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, ix, iy)
  115.     IF ax1 = ax2 THEN 'line a is vertical
  116.         IF bx1 = bx2 THEN ' b is vertical
  117.             IF ax1 = bx1 THEN lineIntersectLine% = -1 ' if x's are same it is same vertical line
  118.             EXIT FUNCTION '
  119.         ELSE
  120.             ix = ax1
  121.             slopeYintersect bx1, by1, bx2, by2, m2, y02
  122.             iy = m2 * ix + y02
  123.             lineIntersectLine% = 1 'signal a point was found
  124.             EXIT FUNCTION
  125.         END IF
  126.     ELSE
  127.         slopeYintersect ax1, ay1, ax2, ay2, m1, y01 ' -m = a, 1 = b, y0 = c  std form
  128.     END IF
  129.     IF bx1 = bx2 THEN 'b is vertical
  130.         ix = bx1: iy = m1 * ix + y01: lineIntersectLine% = 1 'signal a point was found
  131.         EXIT FUNCTION
  132.     ELSE
  133.         slopeYintersect bx1, by1, bx2, by2, m2, y02 ' -m = a, 1 = b, y0 = c  std form
  134.     END IF
  135.     d = -m1 - -m2 ' if = 0 then parallel or equal because slopes are same
  136.     IF d THEN 'otherwise about 0 <<< tighten down from .2 to .05
  137.         ix = (y01 - y02) / d: iy = (-m1 * y02 - -m2 * y01) / d
  138.         lineIntersectLine% = 1 'signal one intersect point was found
  139.     END IF
  140.  

 
Two Triangles Overlap.PNG


Using the overlap signal from the code in Best Answer was getting some really screwy lines, messing up the outlines way, way more than helping with anything. Phooey all that effort... oh well.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Intersect of 2 lines carried a step further
« Reply #28 on: March 18, 2020, 07:26:51 am »
Alrighty - so I'm (in a rush as usual) trying to piece together if there are any remaining questions. Would you say this question is fully cooked now? FWIW the intersection calculations are way simpler with vectors, and only one IF statement is technically needed. (The two CIRCLE statements put two copies of the same circle in the same place so this code can basically be cut in half again for the minimalist approach.)

Code: QB64: [Select]
  1.     DIM db AS Vector
  2.     db.x = Segments(2).b.x - Segments(1).b.x
  3.     db.y = Segments(2).b.y - Segments(1).b.y
  4.     qj = DotProduct(db, Segments(1).t)
  5.     ql = DotProduct(db, Segments(2).t)
  6.     p = DotProduct(Segments(1).t, Segments(2).t)
  7.     pp = p * p
  8.     IF (pp < 1) THEN
  9.         alphaj = (qj - p * ql) / (1 - pp)
  10.         alphal = (p * qj - ql) / (1 - pp) ' This is actually redundant (along with anything depending on it.)
  11.         IF ((alphaj > Segments(1).alpha1) AND (alphaj < Segments(1).alpha2)) THEN
  12.             IF ((alphal > Segments(2).alpha1) AND (alphal < Segments(2).alpha2)) THEN
  13.                 CALL ccircle(Segments(1).b.x + alphaj * Segments(1).t.x, Segments(1).b.y + alphaj * Segments(1).t.y, 5, 15)
  14.                 CALL ccircle(Segments(2).b.x + alphal * Segments(2).t.x, Segments(2).b.y + alphal * Segments(2).t.y, 5, 15)
  15.             END IF
  16.         END IF
  17.     ELSE
  18.         ' Parallel case.
  19.     END IF
« Last Edit: March 18, 2020, 07:30:06 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Intersect of 2 lines carried a step further
« Reply #29 on: March 18, 2020, 11:05:51 am »
Alrighty - so I'm (in a rush as usual) trying to piece together if there are any remaining questions. Would you say this question is fully cooked now? FWIW the intersection calculations are way simpler with vectors, and only one IF statement is technically needed. (The two CIRCLE statements put two copies of the same circle in the same place so this code can basically be cut in half again for the minimalist approach.)

Code: QB64: [Select]
  1.     DIM db AS Vector
  2.     db.x = Segments(2).b.x - Segments(1).b.x
  3.     db.y = Segments(2).b.y - Segments(1).b.y
  4.     qj = DotProduct(db, Segments(1).t)
  5.     ql = DotProduct(db, Segments(2).t)
  6.     p = DotProduct(Segments(1).t, Segments(2).t)
  7.     pp = p * p
  8.     IF (pp < 1) THEN
  9.         alphaj = (qj - p * ql) / (1 - pp)
  10.         alphal = (p * qj - ql) / (1 - pp) ' This is actually redundant (along with anything depending on it.)
  11.         IF ((alphaj > Segments(1).alpha1) AND (alphaj < Segments(1).alpha2)) THEN
  12.             IF ((alphal > Segments(2).alpha1) AND (alphal < Segments(2).alpha2)) THEN
  13.                 CALL ccircle(Segments(1).b.x + alphaj * Segments(1).t.x, Segments(1).b.y + alphaj * Segments(1).t.y, 5, 15)
  14.                 CALL ccircle(Segments(2).b.x + alphal * Segments(2).t.x, Segments(2).b.y + alphal * Segments(2).t.y, 5, 15)
  15.             END IF
  16.         END IF
  17.     ELSE
  18.         ' Parallel case.
  19.     END IF

If you put your code into a sub routine (SUB or FUNCTION) I will test it in my code tester app but your "simple" thing has need of two Types at least and at least 2 supplemental helper routines, maybe just one DotProduct (and how many supplements might that have?) because I am NOT looking for drawing, just a FUNCTION that returns True if there is an Intersect and gives the intersect point (ix, iy) say.

If you can by-pass the case of vertical lines when the Determinate = 0 without more code to cover that case I am all eyes because that's what takes up the majority of my Intersect FUNCTION.

Hmm... if just going for Intersect maybe I can combine LineIntersect with SegmentIntersect but seems both might come in handy in app.

What's your DotProduct Function, I might be able to put it all together in a tester. I will call my Point Type XY and segments will just be two points. BUT first guarantee you have vertical line cases covered ;-))

Not cooked at all! Nobody has tested another's code and approved. The code I have quoted above is obviously pulled out of some other context and is incomplete to run.


Update: Oh I see the context! (Reply #24) from first code, OK I will work up test for my own satisfaction anyway. ;)
« Last Edit: March 18, 2020, 11:18:25 am by bplus »