0
$\begingroup$

I'm having a little trouble solving this (ok, a lot of trouble).

I hate to come here with it and bother you all, but I could really use some help.

I'm creating a graphical display where I am dynamically calculating the dimensions to draw some text within.

I've determined that my equation is: \begin{align}r &= \frac{h}{w} \\ w &= d - d\sin(2 \pi \frac{h}{d}) \end{align}

If somebody knows how to work MathJax and wants to make this pretty, it would be much appreciated!

I am trying to solve for d in terms of r.

I really feel like I am over-complicating this and would like another set of eyes on it.

Thanks!

UPDATE

So, according to the comments below, it appears that this equation cannot be solved algebraically for d, which really stinks.

Here is what I am trying to do:

I am drawing a donut chart using HTML5 Canvas.

As a parameter to my Angular JS directive, I accept a string to be displayed in the middle of the donut chart.

I would like to display this text as large as possible while still fitting inside of the chart with some padding.

I have a few variables known:

1) I know my charts internal radius. 2) I know my font. 3) I know the text that I want to draw.

I can determine a relationship between the text width and the text height by setting the font size of my canvas to an arbitrary size and measuring the text.

I now know that at font-size X, my font-height is X (equal to font-size) and my font width is W for the given text.

Knowing this ratio relating to my font dimensions, I would like to draw my text as large as possible with the corners of the text just touching the edges of the circle with a known radius.

Let's call the known radius r. Call the font-dimension ratio s. Call the desired font-width w.

Any ideas on how to solve for w using s and r? Thanks!

$\endgroup$
17
  • $\begingroup$ is it $$r=\frac{h}{w}$$ and $$w=d-\sin\left(\frac{h}{d} 2\pi \right)d$$? $\endgroup$ Mar 3, 2017 at 20:55
  • $\begingroup$ Is my edition what you meant? $\endgroup$
    – ajotatxe
    Mar 3, 2017 at 20:56
  • $\begingroup$ It's not possible to solve for $d$ using algebra alone. In general, problems of the form $x\sin(x)=y$ are not solvable for $x$. If I may recommend, numerical methods can help you approximate $d$, if that suffices. $\endgroup$ Mar 3, 2017 at 21:01
  • $\begingroup$ As I see it, you're not going to have any luck getting an explicit equation in terms of d. You'll need to get down to an equation like $d = h/(r(1-\sin(2 \pi h/d)))$ and solve this equation numerically. $\endgroup$ Mar 3, 2017 at 21:02
  • 1
    $\begingroup$ If you know LaTeX, it looks like a subset of it. $\endgroup$
    – Bernard
    Mar 3, 2017 at 21:06

1 Answer 1

1
$\begingroup$

We may partially solve for $d$ as follows:

$$w=d-d\sin\left(2\pi\frac hd\right)=d\left[1-\sin\left(2\pi\frac hd\right)\right]$$

$$d=\frac w{1-\sin\left(2\pi\frac hd\right)}$$

One may then apply simple fixed-point iteration:

$$d_1=\frac w{1-\sin\left(2\pi\frac h{d_0}\right)}$$

$$d_2=\frac w{1-\sin\left(2\pi\frac h{d_1}\right)}$$

$$\vdots\\d_{n+1}=\frac w{1-\sin\left(2\pi\frac h{d_n}\right)}$$

And as $n\to\infty$, $d_n\to d$.

We may also apply Newton's method:

$$d_{n+1}=d_n-\frac{d_n-w-d_n\sin\left(2\pi\frac h{d_n}\right)}{1-\sin\left(2\pi\frac h{d_n}\right)+\frac{2\pi}{d_n}\cos\left(2\pi\frac h{d_n}\right)}$$

which converges much faster than fixed-point.

$\endgroup$
2
  • $\begingroup$ WOW! Thank you! This is perfect! $\endgroup$ Mar 3, 2017 at 23:11
  • $\begingroup$ :D No problem, always welcome to help. I will mention, Newton's method will probably converge in only a few iterations, though it is harder to produce Newton's method for problems without calculus. $\endgroup$ Mar 3, 2017 at 23:12

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.