2
$\begingroup$

I would like to know why the intersection of the 2 lines computed with FindInstance is not drawn at the intersection of the 2 lines. Thank you.

point1 = {57.7538, 44.0056};
point2 = {57.7607, 43.9983};
line1 = Line[{point1, point2}];
line2 = Line[{{54.3101, 40.715}, {58.4058, 44.624}}];
intersectionPoint = 
  First[{x, y} /. 
    FindInstance[{x, y} ∈ line1 && {x, y} ∈ 
       line2, {x, y}]];
Graphics[{{Gray, line1}, {PointSize[Large], 
   Point[{point1, point2}]}, {PointSize[Large], Red, 
   Point[intersectionPoint]}}, Prolog -> {Thick, Dashed, line2}]

Graphics of the intersection point

$\endgroup$
  • 1
    $\begingroup$ Provided code works fine for me. Have you tried restarting your kernel? $\endgroup$ – kirma Mar 19 '17 at 14:35
  • $\begingroup$ Works for me, too. $\endgroup$ – m_goldberg Mar 19 '17 at 14:38
  • $\begingroup$ @m_goldberg I see the point not on the intersection like the OP, on v11.0.1 x64 with windows 10. It is quite weird because if you remove the Dashed it shows correctly $\endgroup$ – glS Mar 19 '17 at 14:44
1
$\begingroup$

Not an answer, but another comment that requires graphics.

I am running V11.0.1 on OS X 10.10.2 (Yosemite) and this is what I see.

Graphics[
  {{Gray, line1},
   {PointSize[Large], Point[{point1, point2}]}, 
   {PointSize[Large], Red, Point[intersectionPoint]}}, 
  Prolog -> {Thick, Dashed, line2}]

plot1

The Prolog option is only needed because line2 is much longer than line1 and would totally dominate the plot. Putting it in a prolog means line2's end points are ignored for setting the plot range (it gets clipped). The option can be eliminated by scaling line2 about the intersection.

Graphics[
  {{Gray, line1},
   {Thick, Dashed, Scale[line2, .002, intersectionPoint]},
   {PointSize[Large], Point[{point1, point2}]},
   {PointSize[Large], Red, Point[intersectionPoint]}}]

plot2

In both case, the intersection is drawn correctly. I can only conclude the problem is OS dependent.

$\endgroup$
  • $\begingroup$ Scaling line2 about the intersection works. Thank you for your help. Kind regards. $\endgroup$ – Grégory Gautier Mar 19 '17 at 15:23
1
$\begingroup$

More an observation than an answer (I post it here because I cannot put figures in comments). The behaviour seems to be caused by the Dashed attribute, and it is the line, not the point, that is not drawn correctly.

Op's code for me (v11.0.1 x64 on Windows 10) produces

point1 = {57.7538, 44.0056};
point2 = {57.7607, 43.9983};
line1 = Line[{point1, point2}];
line2 = Line[{{54.3101, 40.715}, {58.4058, 44.624}}];
intersectionPoint =
  First[{x, y} /.
    FindInstance[{x, y} ∈ line1 && {x, y} ∈
       line2, {x, y}]];
Graphics[{
  {Gray, line1},
  {PointSize[Large], Point[{point1, point2}]},
  {PointSize[Large], Red, Point[intersectionPoint]}
  },
 Prolog -> {Dashed, line2},
 Frame -> True, ImageSize -> Large
 ]

Removing the Dashed attribute in the Prolog option, I get:

point1 = {57.7538, 44.0056};
point2 = {57.7607, 43.9983};
line1 = Line[{point1, point2}];
line2 = Line[{{54.3101, 40.715}, {58.4058, 44.624}}];
intersectionPoint =
  First[{x, y} /.
    FindInstance[{x, y} ∈ line1 && {x, y} ∈
       line2, {x, y}]];
Graphics[{
  {Gray, line1},
  {PointSize[Large], Point[{point1, point2}]},
  {PointSize[Large], Red, Point[intersectionPoint]}
  },
 Prolog -> {line2},
 Frame -> True, ImageSize -> Large
 ]

Drawing line2 inside the same Graphics as the rest of the objects doesn't change this, so it doesn't look like a problem in Prolog.

Even better, the lower the Dashing, the further away the line is drawn from the intersection point:

point1 = {57.7538, 44.0056};
point2 = {57.7607, 43.9983};
line1 = Line[{point1, point2}];
line2 = Line[{{54.3101, 40.715}, {58.4058, 44.624}}];
intersectionPoint =
  First[{x, y} /.
    FindInstance[{x, y} ∈ line1 && {x, y} ∈
       line2, {x, y}]];
Graphics[{
  {Gray, line1},
  {PointSize[Large], Point[{point1, point2}]},
  {PointSize[Large], Red, Point[intersectionPoint]}
  },
 Prolog -> Map[{Hue[10 #], Dashing@#, line2} &]@Range[0, .5, 0.01],
 Frame -> True, ImageSize -> Large
 ]

I have no idea why this happens.

$\endgroup$
  • $\begingroup$ Ok, thank you for your help. Kind regards $\endgroup$ – Grégory Gautier Mar 19 '17 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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