4
$\begingroup$

Let's suppose we have a line with a known length $L$ that we transform from a straight line to a curved one matching a semi-circle.

enter image description here

Is there a way to find a formula for the height of the smallest rectangle containing that line? (the width of that rectangle will be the variable)

We can consider the thickness of the line to be equal to $1$.

We have $f(L) = 1$ and $f\left(\frac{2L}{\pi}\right) = \frac{L}{\pi}$

What about $f(x)$ where $\frac{2L}{\pi}\le x \le L$ ?

It will be something for the web, so if it's not possible to find the exact formula and we can approximate it, then it's fine. Having a few pixels off won't be a big deal in my case.

$\endgroup$
13
  • $\begingroup$ I feel like I am misunderstanding your question, the smallest rectangle containing that line would be a rectange with height $1$ (the width of the line) and base $L$. $\endgroup$ Commented 16 hours ago
  • $\begingroup$ @ApexPandora that's when the line is a straight one. I want to find the formula when we curve the line (from straight to curved) $\endgroup$ Commented 15 hours ago
  • $\begingroup$ If it's a semicircle with radius $R$, the width is $2R$ and the height is $R$. If you bend the line such as the outer part has length $L=\pi R$, you get the width $2L/\pi$ and the height $L/\pi$ $\endgroup$ Commented 15 hours ago
  • $\begingroup$ @TemaniAfif, I think curve might be a better suited word here since line implies it being straight, which only refers to the trivial case. $\endgroup$ Commented 15 hours ago
  • 1
    $\begingroup$ You don't just transform a line to a semicircle. You have a whole family of curves that you parameterize by a parameter $x,$ and you want to say something about each value of $x.$ This should be made clear earlier in the question. I think you imagine that "transform" implies all these intermediate forms, but it does not: mathematically, to "transform" something describes a relationship between the starting state and the final state only and says nothing about anything "in between." $\endgroup$ Commented 7 hours ago

4 Answers 4

6
$\begingroup$

Let $R$ be the radius of the circle. Then the arc of length $L$ corresponds to a central angle $L/R$. Then in your picture, $$ \frac{x}{2R} = \sin(L/2R). $$ When you know $x$ the height of the rectangle is $$ R-\sqrt{R^2 - (x/2)^2} . $$

Finding $R$ from $x$ is hard: $$ x = 2R\sin(L/2R). $$ but there is no nice formula that solves for $R$ in terms of $x$. You can solve it numerically for any particular value of $x$.

$\endgroup$
2
  • $\begingroup$ That's my issue .. finding the trig formulas is not hard but Finding R from L and x to, then, find the height is where I am stuck. $\endgroup$ Commented 14 hours ago
  • $\begingroup$ You are stuck for good reason. There is no formula. Since you need this in code, you may find a fast enough numerical algorithm $\endgroup$ Commented 14 hours ago
4
$\begingroup$

This is actually nothing other than the extremely surprising Railroad Track Problem that is wonderfully written about in Forman S. Acton's Numerical Methods That (usually) Work. What follows is a full solution, so you might want to stop reading my answer and instead go read the book, if you do not want spoilers.

The existing solutions above are correct that you do have to find a numerical solution. But they are not developed enough. With a bit more work, you can get something much more useful.

It is not nice to work with $L$ and $x$, but instead $\dfrac L2$ and $\dfrac x2$ are much more convenient. $$ \begin{align} \tag1R\sin\vartheta&=\frac x2\\ \tag2R \vartheta&=\frac L2\\ \tag3h&=R(1-\cos\vartheta) \end {align} $$ I am using a geometry similar to that in the Wolfram link, but with a replacement of notation to yours.

Now, as $x\to L$, the interpretation is that $R\to\infty$ and $\vartheta\to0$, and you should be able to see that the equations can be made to work. The result is that $h\to0$, so your function $f(x)=h+1$, adding the one just to take care of the thickness of the line.

Those equations have both $R$ and $\vartheta$ intertwined, but if you find $\vartheta$ in any way, then Equation (2) gives you a way to find $R$, so then you can solve the whole thing. Dividing Equations (1) and (3) by Equation (2), we get $$ \begin{align} \tag4\text{sinc}\,\vartheta\overset{\text{def}}=\frac{\sin\vartheta}\vartheta&=\frac xL\\ \tag5h&=\frac L2\cdot\frac{1-\cos\vartheta}\vartheta=\frac L2\cdot\frac{2\sin^2\frac\vartheta2}{2\frac\vartheta2}=\frac L2\cdot\frac\vartheta2\text{sinc}^2\frac\vartheta2 \end {align} $$ And so it turns out, the solution does not depend upon knowing $R$ at all. That is, from Equation (4), you numerically find the value of $\vartheta$, and then in Equation (5) you can compute everything. The sinc function is implemented in basically every computer maths library and so computing it in Equation (5) is super easy and cheap.

However, the inverse, as needed in Equation (4), is much less used, and much less implemented. In the limit $x\to L$, simply expand the sinc function as a Taylor series, keeping two terms to get the first estimate for $\vartheta$, and then you can unleash Newton–Raphson method to get incredibly good approximations extremely quickly and cheaply, and in this case it is guaranteed to work wonderfully.

As for when $0\leqslant x\ll L$, it is then safe to start with the approximation $\frac{\sin\vartheta}{\frac\pi2}\approx\frac xL$ and then use Newton–Raphson on it yet again. That is, Newton–Raphson is basically the main workhorse that you can even implement on a school scientific calculator.

$\endgroup$
5
  • $\begingroup$ This is a good reference but it does not address the complete problem. The "railroad track" problem is a special case of the OP's problem where the thickness of the line is zero. Because the line has thickness, the bounding box has extra height. Fortunately, the extra height is a simple function of $\theta.$ $\endgroup$ Commented 7 hours ago
  • $\begingroup$ We can get Equation $(4)$ directly from Ethan Bolker's answer by substituting $\frac{L}{2R} = \theta.$ It is true that you can work the entire problem then using only $\theta$ and $L$ with no explicit use of $R.$ $\endgroup$ Commented 7 hours ago
  • $\begingroup$ I overestimated the extra height by simply adding 1 to h. $\endgroup$ Commented 6 hours ago
  • $\begingroup$ I see. If I understand the question correctly, $h+\cos\theta$ would work. $\endgroup$ Commented 2 hours ago
  • $\begingroup$ Yes, I agree. That would be a proper solution. $\endgroup$ Commented 1 hour ago
2
$\begingroup$

What you are looking for is an arc, not a semicircle. Let's suppose that the radius is $R$, and the angle from the center is $2\alpha$. Then $$L=2\alpha R$$ The width of the rectangle is $2R\sin\alpha$. The height of the rectangle containing only the outer edge of the line is then $$R-R\cos\alpha$$. If you want to include the thickness of the line, you need to add $1\cos\alpha$.

$\endgroup$
1
  • $\begingroup$ I somehow identified those formulas but what I want is to express the Height based on the Width. is there a way to do that? I am not able to find how to transform the equations to get H = f(W) $\endgroup$ Commented 14 hours ago
2
$\begingroup$

Your question is essentially to find $y$ as a function of $x$ in the diagram below, where $L$ is the length of the outer arc:

Diagram of a curved band shaped like part of a ring, with a tight bounding rectangle showing its width and height.

As others have shown, this doesn't have a closed form solution. If you allow $\text{sinc}^{-1}(u)$ to mean "the unique $t\in[0,\pi/2]$ such that $\sin t = ut$", then we can write the solution as

$$ y = \cos\left(\text{sinc}^{-1} \frac{x}{L}\right) + \frac{x}{2}\tan\left(\frac{1}{2}\text{sinc}^{-1}\frac{x}{L}\right) $$

However, if you mean to actually calculate a number, you'll want to use a numerical method to compute $t = \text{sinc}^{-1}\frac{x}{L}$ and compute $y = \cos t + \frac{x}{2} \tan \frac{t}{2}$.

One polynomial-ish approximation is

$$ \text{sinc}^{-1}(u) \approx \sqrt{6\left(1-u\right)}\left(1+\frac{3}{20}\left(1-u\right)+\frac{321}{5600}\left(1-u\right)^{2}\right) $$

which is better when $t$ is closer to $1$ (i.e. straighter lines), but is only off by at most about 0.13% ($y$-error relative to $x$ for large $L$). If that's good enough for your application, it might be easier than implementing an iterative method like Newton-Raphson for just this.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.