11
$\begingroup$

I want to mark all points inside of a triangle having the following property:

I can center a line segment of length $c$ on the point so that the line segment is entirely contained inside the triangle.

See the figure below that I created by hand. The gray points have the property because I can center such a line segment there. Exemplary line segments are depicted in black.

Is there any way to produce a plot that visualizes this property?

Actually, I do not know how to start here.

Visualization of the points (done by hand)

$\endgroup$
6
  • $\begingroup$ So I understand, is your constraint equivalent to seeking all points inside the triangle whose distance from the edges is at least $c/2$? Or are there further restrictions on the orientation of the segment (eg horizontal)? $\endgroup$
    – MarcoB
    Sep 10 at 13:43
  • $\begingroup$ Not exactly. I added a figure that I created by hand (it's currently very small, I try to improve the size). All gray points (approximately) have this property because I can center such a line segment on them. The black line segments are two or three examples. $\endgroup$
    – Jannik
    Sep 10 at 13:50
  • $\begingroup$ Maybe one can say that the points are at a distance of $\frac{c}{2}$ from at least two of the edges. $\endgroup$
    – Jannik
    Sep 10 at 13:57
  • $\begingroup$ Should make more clear the definition of the gray domain. Looks to me you take a line of length $L$. Then define domain $D$ inside the triangle such that you can center this line segment on any point in $D$ and there is at least one orientation of the line that remains in the triangle. Also add at least one point in the triangle examples as an example where centering the line results in part of it outside the triangle. $\endgroup$
    – josh
    Sep 10 at 14:28
  • $\begingroup$ That's exactly what I mean. $\endgroup$
    – Jannik
    Sep 10 at 14:40

2 Answers 2

14
$\begingroup$

Edit

Clear["Global`*"];
pts = {{0., 0.}, {10., 0.}, {5, 8}, {1, 6}} // Map@N // 
   Rationalize[#, 0] &;
reg = Polygon[pts];
L = 8.0 // Rationalize;
conditions = 
  Exists[{x1, y1, x2, 
    y2}, {x1, y1} ∈ reg && {x2, y2} ∈ 
     reg && {x2 - x1, y2 - y1} . {x2 - x1, y2 - y1} >= L^2, 
   x == (x1 + x2)/2 && y == (y1 + y2)/2];
results = Resolve[conditions, Reals] // FullSimplify;
plot = RegionPlot[results, {x, 0, 10}, {y, 0, 10}, PlotPoints -> 80, 
   MaxRecursion -> 4, Prolog -> {EdgeForm[Cyan], FaceForm[], reg}];
domain = DiscretizeGraphics[plot];
nearest = RegionNearest@domain;
pt0 = {x, y} /. FindInstance[results, {x, y}][[1]];
fig[pt_] := 
  Module[{instance, vector}, 
   instance = 
    FindInstance[{RegionWithin[reg, Line[{pt - {u, v}, pt + {u, v}}]],
       u^2 + v^2 >= (L/2)^2}, {u, v}];
   vector = If[instance =!= {}, instance[[1]], {u -> 1, v -> 0}];
   Show[plot, 
    Graphics[{Red, AbsolutePointSize[5], Point[pt], 
       Arrow[{pt, pt - L/2 Normalize@{u, v}}], 
       Arrow[{pt, pt + L/2 Normalize@{u, v}}]} /. vector, 
     PlotRange -> {{0, 10}, {0, 10}}]]];
Manipulate[
 fig[pt], {{pt, pt0}, Locator, 
  TrackingFunction -> {pt = nearest@#; &}}, SaveDefinitions -> True]

enter image description here

Original

  • When L=8.
Clear[pts, reg, L, conditions, results];
pts = {{0, 0}, {10, 0}, {5, 9.}} // Rationalize;
reg = Triangle[pts];
L = 8.0 // Rationalize;
conditions = 
  Exists[{x1, y1, x2, 
    y2}, {{x1, y1} ∈ reg, {x2, y2} ∈ 
     reg, {x2 - x1, y2 - y1} . {x2 - x1, y2 - y1} >= 
     L^2}, {x == (x1 + x2)/2, y == (y1 + y2)/2}];
results = Resolve[conditions, Reals] // FullSimplify;
Show[Graphics[{EdgeForm[Red], FaceForm[], reg}], 
 RegionPlot[results, {x, 0, 10}, {y, 0, 10}, PlotPoints -> 50, 
  MaxRecursion -> 4]]

enter image description here

  • When L=5.

enter image description here

  • We can test convex polygon.
Clear[pts, reg, L, conditions, results];
pts = {{0., 0.}, {10., 0.}, {5., 8.}, {1., 4.}} // Rationalize;
reg = Polygon[pts];
L = 8.0 // Rationalize;
conditions = 
  Exists[{x1, y1, x2, 
    y2}, {x1, y1} ∈ reg && {x2, y2} ∈ 
     reg && {x2 - x1, y2 - y1} . {x2 - x1, y2 - y1} >= L^2, 
   x == (x1 + x2)/2 && y == (y1 + y2)/2];
results = Resolve[conditions, Reals] // FullSimplify;
Show[Graphics[{EdgeForm[Red], FaceForm[], reg}], 
 RegionPlot[results, {x, 0, 10}, {y, 0, 10}, PlotPoints -> 50, 
  MaxRecursion -> 2]]

enter image description here

  • Or random convex polygon.
SeedRandom[10];
reg = RandomPolygon[{"Convex", 5}, DataRange -> {0, 10}];
reg = Polygon@Rationalize[MeshCoordinates[reg], 0]; 
L = 10.0 // Rationalize;
conditions = 
  Exists[{x1, y1, x2, 
    y2}, {x1, y1} ∈ reg && {x2, y2} ∈ 
     reg && {x2 - x1, y2 - y1} . {x2 - x1, y2 - y1} >= L^2, 
   x == (x1 + x2)/2 && y == (y1 + y2)/2];
results = Resolve[conditions, Reals] // FullSimplify;
Show[Graphics[{EdgeForm[Red], FaceForm[], reg}], 
 RegionPlot[results, {x, 0, 10}, {y, 0, 10}, PlotPoints -> 50, 
  MaxRecursion -> 2]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you very much. I learned a lot about Mathematica and also about the regions I defined. $\endgroup$
    – Jannik
    Sep 11 at 8:39
11
$\begingroup$

If we phrase out the problem as "for each point {x, y} in the sought region there exists a line passing through it on which both points at the distance l/2 from {x, y} are inside the triangle", the problem is basically already solved with use of RegionMember, Exists and the Pythagorean theorem.

Pretty similar to the @cvgmt's answer, but anyway:

With[
 {rt = RegionMember[RegularPolygon[3]],
  l = 29/20},
 Resolve[
   Exists[{u, v},
    u^2 + v^2 == (l/2)^2,
    rt[{x, y} + {u, v}] && rt[{x, y} - {u, v}]],
   Reals] //
  RegionPlot[{rt[{x, y}], #},
    {x, -1, 1}, {y, -1/2, 1},
    PlotPoints -> 200, AspectRatio -> Automatic] &]

enter image description here

This of course relies on the fact that triangles are convex. This solution also extends to polygons and other regions that are convex, but Resolve'ing the equations is certainly easiest for plain old triangles.


EDIT:

It can be also shown how the hole in the middle is formed by tracing midpoints of line segments whose both ends reside on the triangle boundary:

With[
  {poly = RegularPolygon[3],
   l = 29/20},
  With[
   {background =
     With[{rt = RegionMember[poly]},
      Resolve[
        Exists[{u, v},
         u^2 + v^2 == (l/2)^2,
         rt[{x, y} + {u, v}] && rt[{x, y} - {u, v}]],
        Reals] //
       RegionPlot[{rt[{x, y}], #},
         {x, -1, 1}, {y, -1/2, 1},
         PlotPoints -> 200, AspectRatio -> Automatic] &]},
   With[
    {boundary = RegionBoundary[poly]},
    Table[With[
      {o = RegionIntersection[boundary,
          Line[{{0, 0}, {Sin[a], -Cos[a]}}]][[1, 1]]},
      Show[
       {background,
        Graphics[{Line[{o, #}],
            Point[{o, Midpoint[{o, #}], #}]} & /@
          RegionIntersection[Circle[o, l], boundary][[1]]]}]],
     {a, 0., 2 Pi, Pi/60}]]]] // ListAnimate

enter image description here

$\endgroup$
4
  • $\begingroup$ Why should there be a hole in the middle of your feasible region? Shouldn't points in the middle of the triangle be included as well? $\endgroup$
    – MarcoB
    Sep 10 at 17:31
  • $\begingroup$ @MarcoB The same occurs also with @cvgmt's solution. If you insert Epilog -> {Red, PointSize[Large], Point[{0, -1/4}], Arrowheads[{-1, 1}/20], Arrow[{{-29/40, -1/4}, {29/40, -1/4}}]} you can see that there is simply no space for the line segment midpoint to fit in the interior area... $\endgroup$
    – kirma
    Sep 10 at 17:50
  • $\begingroup$ (+1) Good idea of using the vector {u,v} instead of two points, very faster! $\endgroup$
    – cvgmt
    Sep 10 at 22:50
  • $\begingroup$ Thank you so much. Unfortunately, I could only accept one answer. $\endgroup$
    – Jannik
    Sep 11 at 8:37

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.