# Using math for interior decorating with lamps

When I was in college, I owned three lamps and had a dark apartment. I kept trying to position them in different areas of the room, but it was still dark. Then I decided to model the problem with math: given three light sources of equal strength in a rectangular solid of a room, where can you place them to maximize the average value of the amount of light reaching a point in the solid?

Then I realized that the asymptotes at the light bulbs themselves would make the average diverge.

Recently, I thought of a reformulation:

Given three light sources in a rectangular solid of a room (assume height of ten feet, width of 15 and length if 25),all at height 6 ft., where should they be placed to maximize the average value (Edit: Minimum value) of the intensity of the light on the plane at height 3.5 ft.? (Since the couches are that height).

Alternatively, if someone can give a more accurate reformulation of this problem (perhaps involving reflections of the wall) and solve it, that would be much cooler.

-
Are you sure you want to optimise the average light intensity and not say the minimum light intensity? It seems to me that the solution to your problem as currently posed is to place all three light bulbs in the exact centre of the room. – Abel Jun 3 '13 at 17:24
Good point! Smooth lighting is much better in real life than having areas with huge light. I actually was trying last night to brighten up a room for a camera and ended up putting a lamp in the middle of the floor, and it was not optimal... – Brian Rushton Jun 3 '13 at 17:28
Would it make sense to attempt to minimize the average distance from the closest light? The optimum would no longer be all in the center and this method would attempt to drive lamps away from each other but also away from the walls. (@Abel is seems like I should make a joke but this isn't the right place) – kaine Jun 3 '13 at 17:33
@kaine Your suggestion makes for an interesting optimisation problem, but I think physically the light intensity at a point should be proportional to $a^{-2}+b^{-2}+c^{-2}$, where $a$, $b$ and $c$ are the distances to the different lamps. Also nice one, if you mean the joke I think you mean. – Abel Jun 3 '13 at 17:46
The response to a light stimulus isn't directly proportional to the stimulus. Rather it's proportional to the logarithm of the stimulus - this is the "Weber-Fechner law" (en.wikipedia.org/wiki/Weber%E2%80%93Fechner_law). So maybe work with $\log (a^{-2} + b^{-2} + c^{-2})$. This is both psychophysically more realistic and won't diverge as badly around the lights themselves. In particular you can calculate the average light level in the room, which you couldn't do without the logs. – Michael Lugo Jun 3 '13 at 20:58

It's not super hard to write down a model for your problem. Performing the numerical optimization is a bit of a challenge, however!

The basic idea

Here's the simplest approach to the originally stated problem not including reflection. Given lamp locations $(x_1,y_1)$, $(x_2,y_2)$, and $(x_3,y_3)$, together with a point $(x,y,z)$ in the room, we denote the intensity of the light at the point by

$$i_{x_1,y_1,x_2,y_2,x_3,y_3}(x,y,z) = \sum_{k=1}^3 \frac{1}{(x-x_k)^2+(y-y_k)^2+(z-6)^2}.$$

This simply states the well known fact that intensity of light a distance $d$ from a light source is proportional to $1/d^2$. I assume also that intensity is additive.

Then, given $(x_1,y_1)$, $(x_2,y_2)$, and $(x_3,y_3)$, we would define $m(x_1,y_1,x_2,y_2,x_3,y_3)$ to be the minimum value of $i_{x_1,y_1,x_2,y_2,x_3,y_3}(x,y,z)$ subject to the restrictions that $0\leq x \leq 25$, $0\leq y \leq 15$, and $0\leq z\leq 10$. (In the reformulated problem, we have $z=3.5$. This seems to reduce the complexity by one dimension, but a natural guess for the original problem was that the minimum would occur on the floor.)

Finally, maximize $m(x_1,y_1,x_2,y_2,x_3,y_3)$ subject to $0\leq x_k \leq 25$ and $0\leq y_k \leq 15$.

Reducing the search space

Unfortunately, the numerics are quite challenging. We first minimize $i$ as a function of 2 variables to obtain a numerically defined function which we then maximize as a function of 6 parameters. It would be particularly good if we could reduce the number of parameters. This can be done assuming the solution has some sort of symmetry. Given the symmetry of the room, it seems quite likely that the ideal configuration has displays one of the two following symmetries:

Assuming the former, we have $x_2=12.5$, $x_3=25-x_1$, and $y_3=y_1$ in $i_{x_1,y_1,x_2,y_2,x_3,y_3}$, with $x_1$, $y_1$ and $y_2$ free. Assuming the latter, we have $x_3=x_1$, $y_2=7.5$, and $y_3=15-y_1$. In either case, the computation of $m$ now involves the minimization of a numerically computed function of 3 variables. Running a Nelder-Mead constrained optimizer in Mathematica takes minute or so, as opposed to my original approach which took much longer.

I should point out that I have no proof that the correct configuration has this shape - it's just intuition, originating from the fact that my initial approach yielded a shape very much like configuration one.

At any rate, implementing this plan in Mathematica, I came up with a room arrangement that looks something like so:

The lamp locations are approximately: $(5,4.37)$, $(12.5,11.69)$, and $(20,4.37)$. Using the intensity function above, this yields a minimum in the middle of the front wall of about $0.0315224$.

Reflection

It's not much harder to implement Willie Wong's suggested approach to deal with reflection. The $i$ equation becomes

$$i_{x_1,y_1,x_2,y_2,x_3,y_3}(x,y,z) = \sum_{j,\ell=-\infty}^{\infty} \sum_{k=1}^3 \frac{a^{|j|+|\ell|}}{(x-(x_{j,k}-25j))^2+(y-(y_{\ell,k}-15\ell))^2+(z-6)^2},$$

where

$$x_{j,k} = \frac{1}{2} \left(1+(-1)^j\right) x_k+\frac{1}{2} \left(1-(-1)^j\right) \left(25-x_k\right)$$ and $$y_{\ell,k} = \frac{1}{2} \left(1+(-1)^{\ell }\right) y_k+\frac{1}{2} \left(1-(-1)^{\ell }\right) \left(15-y_k\right).$$

Note that $x_{k,j}$ is simply either $x_k$ or its reflection $25-x_k$, depending on whether $j$ is even or odd.

The constant $a$ is between zero and one and is called albedo or the reflection coefficient. I took $a=1/2$, though I have no real data on what would be appropriate. Of course, we also must truncate the sum. In my code, I allowed $j$ and $\ell$ to run from $-3$ to $3$. I have not considered reflection off of the floor or ceiling. Perhaps the floor is carpeted and the ceiling has some non-reflective stucco or some such.

Taking all this into account, I came up with the following room:

Asteroids

If we use the somewhat simpler expression for $i$:

$$i_{x_1,y_1,x_2,y_2,x_3,y_3}(x,y,z) = \sum_{j,\ell=-\infty}^{\infty} \sum_{k=1}^3 \frac{a^{|j|+|\ell|}}{(x-(x_k-25j))^2+(y-(y_k-15\ell))^2+(z-6)^2},$$

we obtain an asteroids style, wrap-around room:

The lamp locations now are approximately: $(1.269,1.756)$, $(12.5,10.76)$, and $(23.73,1.756)$. Using the intensity function above, this yields a minimum of about $0.0613712$ at the point $(12.5, 2.291)$.

-
Great picture! I have some faith in this, because this is almost exactly what we've come up with in real life to deal with the lack of light. – Brian Rushton Jun 3 '13 at 19:24
@BrianRushton Real life? That hadn't occurred to me! It is good to know, though, thanks! – Mark McClure Jun 3 '13 at 19:26
@BrianRushton Thanks for the accept. I'd still love to see what someone else might come up with. The numerics are harder than I imagined! – Mark McClure Jun 3 '13 at 20:34
It does not appear that you are implementing any sort of ray-tracing? Typical room walls have non-zero albedo (white paint anywhere from 0.5 to 0.9, and coloured paint a bit lower), which would make the contour shapes different from the ones you plotted. – Willie Wong Jun 4 '13 at 8:29
BTW, since the room is rectangular, one way to model reflection from the wall is to tile the plane with rectangles (copies of the room). Label them by $\mathbb{Z}^2$. For the light originating from room $(k,l)$ attenuate it by $a^{|k| + |l|}$ where $a$ is the albedo $\in [0,1]$. – Willie Wong Jun 4 '13 at 8:33

I realise this is an old question, but looking over the accepted answer I noticed a slight mistake; the minimum intensity in that room is actually in the top-left / top-right corners, but the model got stuck in the local minimum at the bottom (look at the contours). The actual solution, it turns out, is much more boring:

(that's with wall reflectivity of 0.4, which seems about standard for bright painted walls)

This was found by a dumb brute-force approach, dividing the room into discrete lamp positions and trying every possibility. That means no possibility of getting stuck in locally optimal solutions, but also means you have to trade speed for precision. You can find my implementation here (it's JavaScript):

http://htmlpreview.github.io/?https://github.com/davidje13/OptimisationStuff/blob/master/lights.htm

(for some reason it runs twice on that github.io viewer)

But perhaps the other solution is actually more appealing; the front wall is brighter, and the dark back corners aren't really important.

Well, after that I started messing about with the numbers, so here are some more findings:

• 4 lamps are best in a square:

• 5 lamps finally give something interesting: A squashed dice! (looks familiar as a speaker arrangement)

• It looks like 6 lamps are best arranged in two lines of three, but I had to set the resolution quite low to calculate that, so I can't be certain)

• The darker the walls, the closer your lights should be to them (seems counter-intuitive to me), but the general pattern doesn't change.

Finally, for your original question the answer is actually quite simple: maximising the average intensity within the room is the same as maximising the total intensity. Since the bulbs are giving out a fixed amount of light no matter how you arrange them, and that light can only go to the ceiling, walls and floor, the problem becomes one of minimising the total light hitting the walls (ceiling and floor are roughly symmetric). This has an obvious solution: put all the lights in the middle of the room! Perhaps not very practical though. I think your reformulation is much more appropriate for getting balanced lighting.

-