Note: Here we want a line segment $(s_k, e_k)$ to be oriented such that the point $c$ is to the right of the colinear line through $s_k$ to $e_k$.
(BTW, "colinear line" is redundant.) This is a key property. As long as you choose $s_k$ and $e_k$ this way (so $(s_{ky}-c_y)(e_{kx}-c_x) \ge (s_{kx}-c_x)(e_{ky}-c_y)$), the problem has a simple solution. If travelling from $s_k$ to $e_k$ has the circle center on your right, then you are travelling clockwise, and the angle should be decreasing. That is, the argument for $e_k$ should always be less than or equal to the argument for $s_k$.
If this isn't true, there are two ways we can correct it: either add $2\pi$ to the argument of $s_k$ or subtract $2\pi$ from the argument of $e_k$. Which technique makes sense depends on whether we are looking for the rightmost or leftmost segment. And just to be clear, I assume that these mean:
- "Rightmost segment" is, among all segments with at least one end in the sector, the one with the most clockwise argument of all ends (include one outside the sector, provided the other end is in).
- "Leftmost segment" is, among all segments with at least one end in the sector, the one with the most counter-clockwise argument of all ends (include one outside the sector, provided the other end is in).
Note that if the sector happens to open downward (instead of upward as in your examples), the "Rightmost segment" will be on the left and the "Leftmost segment" will be on the right (this is why "clockwise" and "counter-clockwise" are the better terminology for rotational phenomena).
Initialize variables
MinIndex = -1
MaxIndex = -1
MinAngle = 13 # > 4 * pi
MaxAngle = -7 # < -2 * pi
Pass through your segments, skipping over any segment without at least one endpoint in the sector. For the rest,
- If $\arg s_k \ge \arg e_k$, then
- if $\arg s_k >\text{ MaxAngle}$, then $\text{MaxAngle } = \arg s_k, \text{ MaxIndex } = k$.
- if $\arg e_k <\text{ MinAngle}$, then $\text{MinAngle } = \arg e_k, \text{ MinIndex } = k$.
- If $\arg s_k < \arg e_k$, then
- if $\arg s_k + 2\pi >\text{ MaxAngle}$, then $\text{MaxAngle } = \arg s_k + 2\pi, \text{ MaxIndex } = k$.
- if $\arg e_k - 2\pi <\text{ MinAngle}$, then $\text{MinAngle } = \arg e_k - 2\pi, \text{ MinIndex } = k$.
When you are finished, MinIndex will point to the Leftmost segment and MaxIndex will point to the Rightmost.
Most text books which over this Concept generally hand-wave or gloss-over the mathematics behind the Equations.
Yes , I agree with OP that it is not very clear why $ \frac{\partial f(x,y,p)} {\partial p} $ must be $0$.
Eg , the given wiki brushes-off the Issue by claiming $f(x,y,p_1)=0$ & $f(x,y,p_2)=0$ , hence $f(x,y,p_1)-f(x,y,p_2)=0$ & almost "magically" , it concludes that $\frac{f(x,y,p_1)-f(x,y,p_2)}{(p_1-p_2)}=0$ , which is not intuitive : (1) Why not divide by $(p_1-p_2)^2$ ? (2) Why not say the Same for Elementary Differential Calculus to claim that $dy/dx=0$ always ? (3) Why not consider $\frac{\partial f} {\partial x} = 0$ with Same logic ? (4) Why 2 Criteria are enough ?
In short , the given Derivation is incomplete or inaccurate.
It is similar in most other text books too.
I will try to give my intuition & then I will give the Correct Derivation.
Best (Complete) Derivation I came across was in Myskis (Mir Publishers) "Introductory Mathematics for Engineers" & my Elaboration (Calculation) will be utilizing that.
It may look a little too long but it is essential very simple.
![ENVELOPE](https://i.stack.imgur.com/Hrr3i.png)
Consider the Black Envelope & the Grey Isolated Curve & the family of Curves which have that Envelope.
When the left-most Grey curve is intersecting on the left (Point $A$) , the tangents (to the curve & to the Envelope) are Positive but not equal.
At the Intersection on the right (Point $B$) , one tangent is going up while the other is going down.
Naturally , we can see that the Grey Curve can not have the Envelope shown at that Point.
Let us ignore the Grey Curve , which is not in the family of curves & is shown to high-light what the tangents must be like.
Consider the right-most Purple curve.
The tangent to Envelope & the tangent to Curve are coinciding , having Exact Same value at $E$ , the Point of Contact.
This is what we want from 2 Consecutive Curves.
Consider the Central Blue Curve corresponding to some $p$.
To the left , we have the Curve corresponding to $p - \delta p$.
To the right , we have the Curve corresponding to $p + \delta p$.
The Points of Intersection are $C$ & $D$ which lie on the Curves hence $f(x,y,p)=0$.
$C$ : Intersection of $f(x,y,p - \delta p)=0$ & $f(x,y,p)=0$
$D$ : Intersection of $f(x,y,p)=0$ & $f(x,y,p + \delta p)=0$
We can not make $\delta p \equiv 0$ , because all Points between 2 Curves will be Common.
When $\delta p$ tends to $0$ , the Points $C$ & $D$ get closer to the Envelope & will eventually lie on the Envelope.
Here , hand-waving intuition : $f(x,y,p + \delta p) - f(x,y,p) \equiv 0$ , $\frac{f(x,y,p + \delta p) - f(x,y,p)}{\delta p} \equiv 0$ , hence we can "eliminate" $\delta p$ by taking limit when it tends to $0$
Derivation (utilizing material given by Myskis) :
We have $f(x,y,p) = 0$ on the Curves & on the Envelope.
Let $p=C$ , some value , corresponding to a Point on the Envelope , hence $f(x,y,C) = 0$.
Let $y_{envel}(x)$ be the Envelope , while $y_{curv}(x)$ be the Curve at the Point we are focussing on here.
When we move along the Envelope (varying the $x$ co-ordinate) , naturally $C$ will change , that is , $C=C(x)$
Partially Differentiate the given function to get :
$\color{blue}{\frac{\partial f}{\partial x} + \frac{\partial f}{\partial y} \frac{dy_{envel}}{dx}} + \color{green}{\frac{\partial f}{\partial C} \frac{dC(x)}{dx}} = 0 \tag{1}$
When we move along the Curve (varying the $x$ co-ordinate) , we keep $C$ Constant , that is , $\frac{dC}{dx}=0 \tag{2}$
Partially Differentiate the given function to get :
$\color{blue}{\frac{\partial f}{\partial x} + \frac{\partial f}{\partial y} \frac{dy_{curv}}{dx}} + \color{red}{\frac{\partial f}{\partial C} \frac{dC}{dx}} = 0 \tag{3}$
At the Point of Contact between Curve $y_{curv}(x)$ & Envelope $y_{envel}(x)$ , we want the two tangents to be Equal , that is , $\frac{dy_{curv}}{dx}=\frac{dy_{envel}}{dx} \tag{4}$ , which will Equalize the 2 blue Parts in (1) & (3)
In (3) , the red Part is $0$ , hence the remaining blue Part is $0$.
We can plug that into (1) to make the green Part $0$.
In general , We know $C(x)$ is not a Constant in green Part , hence we are left with $ \frac {\partial f} {\partial C} = 0 $
Thus we got what we wanted : $\frac {\partial f} {\partial p} = 0 $
Most text books avoid the Elaborate Details & simply hand-wave to give the Criteria. The exception is Myskis who has given the Details.
Best Answer
$\hspace{3cm}$![](https://i.stack.imgur.com/66PjV.png)
If $\mathcal{C}$ is a straight line you can always rotate and stretch your coordinate system such that $T$ is at $(0,-1)$ and $\mathcal{C}$ is the $x$-axis. If the center of the arc is at $(k,0)$ and its radius is $r$ the location of $P_1$ and $P_2$ is
$$x = k - r \cos \big( \arctan (k) \pm \alpha\big), \quad y = r \sin \big( \arctan (k) \pm \alpha \big)$$
Solving the second equation for $k$ and substituting that into the first equation yields
$$x = \tan \left( \pm \alpha - \arccos \left(\frac y r \right) \right) - \sqrt{r^2 - y^2}$$
where both branches complement each other beacause of the symmetry.
Additionally, if $|k| < \tan(\alpha)$ the arc reaches higher than its endpoints (also, for $\alpha > \frac \pi 2$ the endpoints never reach the top).
If $\mathcal{C}$ is a path of line segments you may have to add a small portion of the arc to the envelope at the connection points of the segments.
You can find the interactive plot here.