POV-Ray : Newsgroups : povray.advanced-users : Stumped by desk lamp trig equation Server Time30 Nov 2022 22:03:38 EST (-0500)
 Stumped by desk lamp trig equation (Message 1 to 8 of 8)
 From: Cousin Ricky Subject: Stumped by desk lamp trig equation Date: 6 Aug 2022 12:24:15 Message: <62ee95af\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62ee95af%241%40news.povray.org",
"headline": "Stumped by desk lamp trig equation",
"dateCreated": "2022-08-06T16:24:15+00:00",
"datePublished": "2022-08-06T16:24:15+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
I want to aim a desk lamp by specifying where it should point.  P(x,y)
is where to aim the lamp, c is the length of the flexible part of the
neck, a is an additional rigid distance to the central axis of the lamp
hood, and f is the angle to bend the neck.  The initial equation was
huge and ugly, but I managed to simplify it considerably, to this form:

(x - c/f) * sin(f) + y * cos(f) = a

But now I'm stuck.  Variables a, c, x, and y are given, and I need to
solve for f.  I plugged it into Wolfram Alpha, but it gave up.  I don't
even know if a paid subscription would find a solution, and I would
hardly use the service enough to justify a subscription anyway.  Does
anyone have an idea of how to proceed with the equation?  Or should I
gamble that Wolfram Alpha Pro can solve it and pay for one month?
```

Attachments:

Preview of image 'flex_lamp_problem.png'

 From: kurtz le pirate Subject: Re: Stumped by desk lamp trig equation Date: 6 Aug 2022 13:32:06 Message: <62eea596\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62eea596%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-06T17:32:06+00:00",
"datePublished": "2022-08-06T17:32:06+00:00",
"author": {
"@type": "Person",
"name": "kurtz le pirate"
}
}
On 06/08/2022 18:24, Cousin Ricky wrote:
> I want to aim a desk lamp by specifying where it should point.  P(x,y)
> is where to aim the lamp, c is the length of the flexible part of the
> neck, a is an additional rigid distance to the central axis of the lamp
> hood, and f is the angle to bend the neck.  The initial equation was
> huge and ugly, but I managed to simplify it considerably, to this form:
>
>   (x - c/f) * sin(f) + y * cos(f) = a
>
> But now I'm stuck.  Variables a, c, x, and y are given, and I need to
> solve for f.  I plugged it into Wolfram Alpha, but it gave up.  I don't
> even know if a paid subscription would find a solution, and I would
> hardly use the service enough to justify a subscription anyway.  Does
> anyone have an idea of how to proceed with the equation?  Or should I
> gamble that Wolfram Alpha Pro can solve it and pay for one month?
>

To test your equation, I replaced the a, c, x and y by numerical values.
Wolfram solve the equation but only numerically because apparently there
is not only one solution...

<https://www.wolframalpha.com/input?i=solve+++%283+-+4%2Fx%29+*+sin%28x%29+%2B+5+*+cos%28x%29+%3D+2>

Puzzled !

--
Kurtz le pirate
Compagnie de la Banquise
```
 From: Cousin Ricky Subject: Re: Stumped by desk lamp trig equation Date: 6 Aug 2022 17:57:21 Message: <62eee3c1\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62eee3c1%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-06T21:57:21+00:00",
"datePublished": "2022-08-06T21:57:21+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
On 2022-08-06 13:32 (-4), kurtz le pirate wrote:
>
> To test your equation, I replaced the a, c, x and y by numerical values.
> Wolfram solve the equation but only numerically because apparently there

Does this imply that I would need to program a numeric solution into my
macro?

> is not only one solution...

I'm only interested in solutions between 0 and pi/2.  The plot of the
solution implies that there can be no more than 2 of these.  With your
example, I'll naturally want the smaller angle, as the larger angle puts
the aim point behind the lamp!

By pushing the aim point farther from the lamp (the bottom plot), I get
only 1 solution.  I'm still trying to work out how to restrict inputs to
the macro to guarantee only scenarios that make physical sense.
```

Attachments:

Preview of image 'flex_lamp_problem-a.png'

 From: kurtz le pirate Subject: Re: Stumped by desk lamp trig equation Date: 7 Aug 2022 10:59:13 Message: <62efd341\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62efd341%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-07T14:59:13+00:00",
"datePublished": "2022-08-07T14:59:13+00:00",
"author": {
"@type": "Person",
"name": "kurtz le pirate"
}
}
On 06/08/2022 23:57, Cousin Ricky wrote:

> Does this imply that I would need to program a numeric solution into my
> macro?

I am afraid that it is not possible to solve literally an equation which
makes appear at the same time t, sin(t) and cos(t). A bit like in
differential equations with x and dx.

Literal solutions never exist (except for school cases).

Another trail.
Let sin(x) = T and cos(x) = U, the equation becomes :
(g - c/x)T + hU - a = 0

Wolfram proposes a more "usable" result.
<https://www.wolframalpha.com/input?i=solve+%28g+-+c%2Fx%29T+%2B+hU+-+a+%3D+0>

x = cT/(-a+gT+hU) with a!=gt+hU & cT!=0

--
Kurtz le pirate
Compagnie de la Banquise
```
 From: Cousin Ricky Subject: Re: Stumped by desk lamp trig equation Date: 7 Aug 2022 13:54:08 Message: <62effc40\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62effc40%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-07T17:54:08+00:00",
"datePublished": "2022-08-07T17:54:08+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
On 2022-08-07 10:59 (-4), kurtz le pirate wrote:
> On 06/08/2022 23:57, Cousin Ricky wrote:
>
>> Does this imply that I would need to program a numeric solution into my
>> macro?
>
> I am afraid that it is not possible to solve literally an equation which
> makes appear at the same time t, sin(t) and cos(t). A bit like in
> differential equations with x and dx.

Then numerical computation it will have to be, albeit in SDL.

> Literal solutions never exist (except for school cases).

I suspected those examples in high school were conveniently contrived.

> Another trail.
> Let sin(x) = T and cos(x) = U, the equation becomes :
> (g - c/x)T + hU - a = 0
>
> Wolfram proposes a more "usable" result.
> <https://www.wolframalpha.com/input?i=solve+%28g+-+c%2Fx%29T+%2B+hU+-+a+%3D+0>
>
> x = cT/(-a+gT+hU) with a!=gt+hU & cT!=0
>
>

I'll take a look at it.  Thanks!
```
 From: Le Forgeron Subject: Re: Stumped by desk lamp trig equation Date: 15 Aug 2022 11:04:46 Message: <62fa608e\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62fa608e%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-15T15:04:46+00:00",
"datePublished": "2022-08-15T15:04:46+00:00",
"author": {
"@type": "Person",
"name": "Le Forgeron"
}
}
Le 07/08/2022 à 19:54, Cousin Ricky a écrit :
> On 2022-08-07 10:59 (-4), kurtz le pirate wrote:
>> On 06/08/2022 23:57, Cousin Ricky wrote:
>>
>>> Does this imply that I would need to program a numeric solution into my
>>> macro?
>>
>> I am afraid that it is not possible to solve literally an equation which
>> makes appear at the same time t, sin(t) and cos(t). A bit like in
>> differential equations with x and dx.
>
> Then numerical computation it will have to be, albeit in SDL.
>
>> Literal solutions never exist (except for school cases).
>
> I suspected those examples in high school were conveniently contrived.
>
>> Another trail.
>> Let sin(x) = T and cos(x) = U, the equation becomes :
>> (g - c/x)T + hU - a = 0
>>
>> Wolfram proposes a more "usable" result.
>> <https://www.wolframalpha.com/input?i=solve+%28g+-+c%2Fx%29T+%2B+hU+-+a+%3D+0>
>>
>> x = cT/(-a+gT+hU) with a!=gt+hU & cT!=0
>>
>>
>
> I'll take a look at it.  Thanks!

If you like complexity, remember that T²+U² = 1,
so U is actually sqrt(1 - T²), reducing the number of variables.
(of course for your setting T & U > 0)

Back to original problem, why is the c part a circle ?

If it is some flexible part, we are back to the evaluation of the length
of a sphere sweep/spline for which there is no formulae, even when it's
just a part of an ellipse.

Do you really need a fixed length c part ?

Can the right angle of the picture (base of light bulb or so) be on the
y axis, with the c segment describing some S-like shape (or
interrogation dot shape )

Why do I want that point on y axis ? Because it is probably better for
the weight of the lamp to be correctly held.

Which make me wonder why there is a straight part after c, but not below it.
```
 From: Cousin Ricky Subject: Re: Stumped by desk lamp trig equation Date: 15 Aug 2022 23:33:44 Message: <62fb1018\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#62fb1018%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-16T03:33:44+00:00",
"datePublished": "2022-08-16T03:33:44+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
On 2022-08-15 11:04 (-4), Le_Forgeron wrote:
> Le 07/08/2022 à 19:54, Cousin Ricky a écrit :
>> On 2022-08-07 10:59 (-4), kurtz le pirate wrote:
>>>
>>> Let sin(x) = T and cos(x) = U, the equation becomes :
>>> (g - c/x)T + hU - a = 0
>>>
>>> [snip]
>>
>> I'll take a look at it.  Thanks!
>
> If you like complexity, remember that T²+U² = 1,
> so U is actually sqrt(1 - T²), reducing the number of variables.

Actually, I already went through that identity on the way to getting the
equation in the OP.  The equation I started with was much more
complicated.  I found that reapplying this identity seemed to take the
equation in a direction that I didn't see as productive, and per Kurtz's
reply above, would have been futile anyway.

> (of course for your setting T & U > 0)

Only for this example.  I had broken down the flexing problem into three
different scenarios depending on how much the lamp was flexed or
extended, but when I worked through the cases separately, they all came
to the exact same equation.  So for my generalized problem, this
restriction no longer applies.

> Back to original problem, why is the c part a circle ?
>
> If it is some flexible part, we are back to the evaluation of the length
> of a sphere sweep/spline for which there is no formulae, even when it's
> just a part of an ellipse.

That is precisely why I am keeping the curve circular.  If you want an
arbitrarily curved neck, I believe Bald Eagle was working on that.  ;-)

> Do you really need a fixed length c part ?

Yes, that is part of how I'm defining the lamp.

> Can the right angle of the picture (base of light bulb or so) be on the
> y axis, with the c segment describing some S-like shape (or
> interrogation dot shape )

The inputs to my macro are simply the position of the lamp and where it
is pointing.  The shape of the neck is not an input I am planning to
include at this time, so I'm just using the most obvious curve to get
the job done.

> Why do I want that point on y axis ? Because it is probably better for
> the weight of the lamp to be correctly held.

I was just concerned with simplifying the math.  Locating the origin at
the bottom of the curve made it easy for me to develop an equation
describing the problem.  Whatever translations need to be made will be
trivial *after* I figure out the angle and radius of curvature.

> Which make me wonder why there is a straight part after c, but not below
> it.

There is a straight part above c because the hood of the lamp is rigid.
The lamp does have a straight part below c, but I have not shown it
because it can be implemented with a simple translation.  There is no
need to involve it in the flexing equation.

Anyhow, as I showed in p.b.i, I did solve the problem.  Taking Kurtz's
word that there is no analytic solution, I wrote a solver, and it works
beautifully.
```
 From: kurtz le pirate Subject: Re: Stumped by desk lamp trig equation Date: 29 Aug 2022 10:22:28 Message: <630ccba4\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#630ccba4%241%40news.povray.org",
"headline": "Re: Stumped by desk lamp trig equation",
"dateCreated": "2022-08-29T14:22:28+00:00",
"datePublished": "2022-08-29T14:22:28+00:00",
"author": {
"@type": "Person",
"name": "kurtz le pirate"
}
}
On 16/08/2022 05:33, Cousin Ricky wrote:
> ...
>
> Anyhow, as I showed in p.b.i, I did solve the problem.  Taking Kurtz's
> word that there is no analytic solution, I wrote a solver, and it works
> beautifully.

I'm back from vacation and this topic is tickling me ;)

Just for fun, I implemented some macros to find the roots of functions
that cannot be determined formally.

I used the methods of Bisection, False Position, Newton Raphson, Secant
and Steffensen

If anyone is interested ...

--
Kurtz le pirate
Compagnie de la Banquise
```