# How to plot the distance between a point moving on a line and the center of a circle

I want to plot a graph that represents the distance of a moving point on a line and the center of a circle, I want to plot the graph on the right (the red dotted graph)

screenshot of an explanatory image:

DynamicModule[{pointOnLine, list},
Manipulate[
Row[{
LocatorPane[
Dynamic@{endA, endB, center},
Graphics[{
{Dashed, Line[{endA, endB}]},
PointSize[0.02], Point[pointOnLine],
{Red, Line[{center, pointOnLine}]}
},
PlotRange -> 10,
Axes -> False, Frame -> True, ImageSize -> Medium
]
],
ListPlot[
list,
PlotStyle -> Red, AspectRatio -> 1,
Axes -> False, Frame -> True, ImageSize -> Medium
]
}],
{{center, {3, 1}}, None},
{{endA, {-5, 5}}, None},
{{endB, {0, -5}}, None},
{{positionAlongLine, 0.3}, 0, 1, Appearance -> "Open",
TrackingFunction -> ((
positionAlongLine = #;
pointOnLine = endB + positionAlongLine (endA - endB);
AppendTo[list, {#, EuclideanDistance[center, pointOnLine]}]
)&)
},
Button["Discard plot points and restart", list = {}],
Initialization :> (
list = {};
pointOnLine = endB + positionAlongLine (endA - endB)
)
]
]


Manipulate[
Row[{Graphics[{
Red,
Circle[{x0, y0}, r]
, Dashed, Black
, Line[{{x1, y1}, {x2, y2}}]
, Line[{{x0, y0}, (1 - t) {x1, y1} + t {x2, y2}}]
, Red, AbsolutePointSize[6]
, Point[(1 - t) {x1, y1} + t {x2, y2}]
, Blue, Point[{x1, y1}]
, Point[{x2, y2}]
, Darker@Green
, Point[{x0, y0}]
}
, Frame -> True
, ImageSize -> 200
, PlotRange -> {{-5, 5}, {-5, 5}}
, GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}}
, GridLines -> Automatic
],
, g = RegionDistance[
Point[{x0, y0}], (1 - t) {x1, y1} + t {x2, y2}];
, Plot[ EuclideanDistance[(1 - x) {x1, y1} + x {x2, y2}, {x0, y0}]
, {x, 0, 1}
, PlotRange -> {{0, 1}, {0, 6}}
, ImageSize -> 200
, PlotLabel -> Style[g, Black, 12]
, GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}}
, GridLines -> Automatic
, Epilog -> {Red, AbsolutePointSize[6]
, Point@{t, g}
, Dashed, Black
, Line[{{t, g}, {t, 0}}]
}
]
}]
,
{{x0, 0}, -1, 1}
, {{y0, 0}, -1, 1}
, {{r, 2}, 0, 4}
, {{x1, 3}, -4, 4}
, {{y1, 3}, -4, 4}
, {{x2, -4}, -4, 4}
, {{y2, -1}, -4, 4}
, {{t, 0.5}, 0, 1}
, TrackedSymbols :> All
]


EuclideanDistance gives the distance between two points. One way to specify a point on your line is

(1-t){a1,b1} + t {a2,b2}


which moves between the two endpoints as t goes from 0 to 1. The distance to the center of the circle is

EuclideanDistance[(1-t){a1,b1} + t {a2,b2}, {x0,y0}]


Giving numerical values to the endpoints and center, you can then plot this distance to get the distance plot. For example, with endpoints {0,3} and {1,0} and circle center at {3,2} gives

My goodness... all this code can be eliminated if you recall Pythagoras' Theorem: $$d = \sqrt{h^2 + s^2}$$ where $$h$$ is the distance from the circle's center to the nearest point on the line (call it $$P$$) and $$s$$ is the distance of the point in question from $$P$$.