2
$\begingroup$

What formula can get a first common point(horizontal) for two parallel lines(segments)? A couple of examples:

First example Second example Third example Fourth example

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, [by clicking the checkmark sign](tinyurl.com/4srwe26 $\endgroup$
    – Dunlop
    Commented Apr 6, 2020 at 8:55

1 Answer 1

7
$\begingroup$

Update: Interactive visualization using IntervalSliders:

DynamicModule[{i1 = {5, 10}, i2 = {6, 11}}, 
 Panel@Column[{Row[{Style["interval 1    ", 16, ColorData[97]@4], 
      Dynamic@Pane[i1[[1]], Alignment -> Right, ImageSize -> {40, 20},
         BaselinePosition -> Center], 
      IntervalSlider[Dynamic[i1], {0, 20, 1}, Method -> "Stop", 
       Appearance -> {"Paired"}, ImageSize -> 400], 
      Dynamic@Pane[i1[[2]], Alignment -> Left, ImageSize -> {40, 20}, 
        BaselinePosition -> Center]}, Spacer[10]], 
    Row[{Style["intersection", 16, ColorData[97]@2], 
      Dynamic@Pane[If[Max[Min /@ {i1, i2}] > Min[Max /@ {i1, i2}], " ", 
         Max[Min /@ {i1, i2}]], Alignment -> Right, 
        ImageSize -> {40, 20}, BaselinePosition -> Center], 
      Dynamic@Graphics[{If[Max[Min /@ {i1, i2}] > Min[Max /@ {i1, i2}], 
       {Thick, Red, Line[{{0, 0}, {20, 0}}]},
       {Orange, CapForm["Round"], AbsoluteThickness[7],
         Line[{{Max[Min /@ {i1, i2}], 0}, {Min[Max /@ {i1, i2}], 0}}],  
        Thick, Gray, Line[{{0, 0}, {20, 0}}],
        Black, PointSize[Medium], 
            Point@{{Max[Min /@ {i1, i2}], 0}, {Min[Max /@ {i1, i2}], 
              0}}}]}, 
      ImageSize -> 400], 
      Dynamic@Pane[If[Max[Min /@ {i1, i2}] > Min[Max /@ {i1, i2}], " ", 
         Min[Max /@ {i1, i2}]], Alignment -> Left, 
        ImageSize -> {40, 20}, BaselinePosition -> Center]}, 
     Spacer[10]], 
    Row[{Style["interval 2    ", 16, ColorData[97]@1], 
      Dynamic@Pane[i2[[1]], Alignment -> Right, ImageSize -> {40, 20},
         BaselinePosition -> Center],
      IntervalSlider[Dynamic[i2], {0, 20, 1}, Method -> "Stop", 
       Appearance -> {"Paired"}, ImageSize -> 400], 
      Dynamic@Pane[i2[[2]], Alignment -> Left, ImageSize -> {40, 20}, 
        BaselinePosition -> Center]}, Spacer[10]]}, 
   Spacings -> {0, -.5}, Alignment -> Center]]

enter image description here

enter image description here

enter image description here

Using NumberLinePlot and IntervalSlider:

nlP = NumberLinePlot[{Interval@First@#, 
     IntervalIntersection @@ Interval /@ #, 
     min = Min[IntervalIntersection @@ Interval /@ #], 
     Interval@Last@#}, 
    Epilog -> If[min === DirectedInfinity[1], {}, 
      Text[Style[min, 14], {min, 2}, {3, 0}]], 
    Spacings -> {1, 1, 0, 1}, 
    Ticks -> {{#, Style[#, 14]} & /@ Flatten[#], Automatic}, ##2, 
    ImageSize -> 1 -> 30, PlotRange -> {{0, 20}, {0, 4}}] &;

DynamicModule[{i1 = {5, 10}, i2 = {6, 11}}, 
 Panel @ Column[{Row[{Style["interval 1    ", 16, ColorData[97]@4], 
      Dynamic@Pane[i1[[1]], Alignment -> Right, ImageSize -> {40, 20},
         BaselinePosition -> Center], 
      IntervalSlider[Dynamic[i1], {0, 20, 1}, Method -> "Stop", 
       Appearance -> {"Paired"}, ImageSize -> 300], 
      Dynamic@Pane[i1[[2]], Alignment -> Left, ImageSize -> {40, 20}, 
        BaselinePosition -> Center]}, Spacer[10]], 
    Row[{Style["interval 2    ", 16, ColorData[97]@1], 
      Dynamic@Pane[i2[[1]], Alignment -> Right, ImageSize -> {40, 20},
         BaselinePosition -> Center],
      IntervalSlider[Dynamic[i2], {0, 20, 1}, Method -> "Stop", 
       Appearance -> {"Paired"}, ImageSize -> 300], 
      Dynamic@Pane[i2[[2]], Alignment -> Left, ImageSize -> {40, 20}, 
        BaselinePosition -> Center]}, Spacer[10]], 
    Dynamic[Panel[#, ImageMargins -> 10] &@
      nlP[{i2, i1}, ImageSize -> 1 -> {30, 25}, 
       PlotRange -> {{0, 20}, {0, 4}}, 
       PlotStyle -> (Directive[CapForm["Round"], #,                 
            AbsolutePointSize[5], AbsoluteThickness[7]] & /@ 
         {ColorData[97]@1, ColorData[97]@2, Black, ColorData[97]@4})]]}, 
   Spacings -> {0, -.5, 1.5}, Alignment -> Center]]

enter image description here

Original answer:

ClearAll[f]
f[i__Interval] := Min @ IntervalIntersection[i] /. Infinity -> {}

f[l__Line] := Module[{int = Interval /@ Sort[{l}[[All, 1, All, 1]]]}, f @@ int]

Examples:

f[Interval[{5, 10}], Interval[{6, 11}]]
6
f[Line[{{5, 1}, {10, 1}}], Line[{{6, 2}, {11, 2}}]]
6
f[Interval[{5, 100}], Interval[{7, 9}]]
7
f[Interval[{5, 10}], Interval[{11, 15}]]
 {}
$\endgroup$
1
  • 1
    $\begingroup$ Similar approach for Intervals: ArgMin[{x, And @@ (Element[{x}, #] & /@ {##})}, x] &. $\endgroup$
    – kirma
    Commented Apr 6, 2020 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.