I have two lines:


I used RegionIntersection to get intersection of these lines, but I can't get the coordinates of the point in the intersection.


Also, I have other two lines and I want their intersection. Later, I want to draw line between these two intersections. For example,


If the intersection of first one is P, and second one Q, I want line PQ. With RegionIntersection I can draw P and Q, but with InfiniteLine I can't draw the line between P i Q. I need their coordinates, or exist other way? I just want to draw the line between them.

  • $\begingroup$ Hi and welcome to Mathematica StackExchange. RegionIntersection[line1,line2] works fine for me. You miss a closing ] in the definition of line1 $\endgroup$
    – mgamer
    Mar 30, 2020 at 11:27
  • $\begingroup$ Thanks. I will correct. $\endgroup$
    – Maja
    Mar 30, 2020 at 13:18

1 Answer 1

line1 = InfiniteLine[{{0, 1}, {4, 2}}];
line2 = InfiniteLine[{{1, 2}, {4, 8}}] ;
line3 = InfiniteLine[{0, 2}, {2, 5}] ;
line4 = InfiniteLine[{7, 1}, {3, 2}];

i12 = RegionIntersection[line1, line2] ;
i34 = RegionIntersection[line3, line4] ;

coords = First /@ {i12, i34}
{{4/7, 8/7}, {-(34/11), -(63/11)}}
line5 = InfiniteLine @ coords;

Graphics[{Opacity[1], AbsolutePointSize[10], 
  Red, line1,
  Blue, line2, 
  Orange, line3, 
  Cyan, line4, 
  Black, line5, 
  Purple, i12, 
  Magenta, i34}, 
 PlotRange -> {{-8, 8}, {-8, 8}}, 
 Axes -> True]

enter image description here

  • $\begingroup$ Thank you so much. I didn't know for First /@. $\endgroup$
    – Maja
    Mar 30, 2020 at 13:13

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.