Start off by looking at the square of the length, as we always do
(since the square-root function is kind enough to be strictly
increasing on the non-negative reals, so we preserve maxima and
minima, but don't have to deal with the square root in
differentiation).
Now, for a given l and theta, what's the optimal shear factor for
max/min length? (I'll denote the shear factor by S rather than SH,
simply because single-letter variables are easier to understand; I'll
also use t for theta.)
We want the minimum value of f(S) = 1 + 2S sin t cos t + S^2 sin^2 t
= 1 + S sin 2t + S^2 sin^2 t.
f'(S) = sin 2t + 2S sin^2 t
= 2 sin t cos t + 2S sin^2 t
= 2 sin t (cos t + S sin t)
= 0 if sin t = 0 or S = -cos t / sin t = -cot t
Now if sin t = 0 we just have l' = l for all values of S, and thinking
about it this makes sense - the y value is constant along the line so
we add the same amount to all the x values, i.e. we're just displacing
the line.
f'(S) = sin 2t + 2S sin^2 t
f''(S) = 2 sin^2 t > 0 where sin t is nonzero, so we have a minimum
(as expected; if S was unbounded then as S went to +/-infinity, so
would the length of any line segment with non-constant y; so our
single critical point must be a minimum).
If S = -cos t / sin t then
f(S) = 1 - 2 cos^2 t + cos^2 t = 1 - cos^2 t = sin^2 t
and therefore l' = l.|sin t| is the minimum length for fixed l, t with
sin t <>0 and for sin t = 0 we have l' = l.
Think about this and it makes sense; if a line is nearly horizontal,
you can shear the x-values in to the middle to make it a very short
vertical line. But if it's absolutely flat you can't, because there's
no difference between the two y-values. So, assuming no constraints on
S and t, you can get as close as you like to 0, but not actually reach
it.
Of course, as sin t gets close to 0, the magnitude of cot t gets
large, so at some point you'll run into either SH_max or SH_min.
(Incidentally, is there any reason why SH_min would not be equal to
-SH_max? Or do you just want as general an answer as possible?) And of
course we also have our limits on t. Now it's time to think about
those limits.
Fortunately l drops out of the equations - for minimum length go with
l_min, for maximum go with l_max, and the ratio of the new length to
the old is independent of l. So we have to consider our boundary as a
square in 2-D (t, S) space, with S going from S_min to S_max and t
from t_min to t_max.
Let's consider interior points first. We know that for any t, the
minimum length will occur when S = -cot t, and for any t in the open
interval (0, pi), if this happens with an S value inside our boundary
there's always room to improve by letting t get a bit closer to the
boundary (0 or pi, whichever is closer) since the length in this case
is l.|sin t|. So *no point inside our boundary is a critical point*.
All critical points in this case must lie on the boundary either of S
or of t.
For instance, suppose t_min was 45 degrees: for any t between 45 and
90 degrees, if S = -cot t is strictly between S_min and S_max we can
move t closer to 45 degrees until we hit either t = t_min or S = S_min
(we're decreasing S in this case, so we won't hit S_max). Which one we
hit first will depend on whether S_min < -cot t_min = -1 in this case,
but we'll wind up on one or the other boundary.
So we only need to look at critical points along each boundary, and we
already know what they will be for t = t_min and t = t_max: S = -cot
t, if that is in the allowed range. Now we need to check the
boundaries S = S_min and S = S_max.
Let g(t) = 1 + S sin 2t + S^2 sin^2 t where S is constant. Then
g'(t) = 2S cos 2t + 2.S^2 sin t cos t
= 2S (cos 2t + S sin 2t)
= 0 if S = 0 or tan 2t = -1/S. (We can also write this as S =
-cot 2t, which is quite similar to the last result.) Note that I'm
implicitly dividing by cos 2t here, but if cos 2t is 0 then sin 2t is
+/-1 and the second factor will only be 0 if S=0, which we have
already covered.
Obviously if S = 0 we get g(t) = 1 along that boundary - if you don't
shear at all, you'll get the original length (well, duh!). Otherwise,
solve tan 2t = -1/S for S=S_min and S=S_max to get the possible values
of t along each boundary. There will be two values of t in [0, pi)
that work for each value of S, and of course you need to check if
they're between t_min and t_max.
In summary, you need to check the following points:
- the four corners: (t_min, S_min), (t_max, S_min), (t_min, S_max),
(t_max, S_max).
- limits of t: (t_min, -cot t_min), (t_max, -cot t_max) if the
S-values are inside the limits for S
- limits of S: (t1, S_min), (t2, S_min), (t3, S_max), (t4, S_max)
where t1 = -arctan (1/S_min) or -arctan(1/S_min) + pi/2, depending on
whether S_min is negative or positive, and t2 = t1 + pi/2; similarly
for t3 and t4, with S_max replacing S_min. If S_min or S_max is 0,
omit the corresponding points here. If they're both 0, this analysis
could have been *very* much shorter. ;-)
Calculate the length ratio at these points and you will get both the
maximum and the minimum.
Now it looked earlier as though we would be able to get the length
arbitrarily small but not 0, but here I am telling you that you only
have to check at most 10 points to get the minimum length. Why? Simply
because to get the length arbitrarily small we have to be able to make
t close to 0 or pi (which we can do if t_min = 0 or t_max = pi) and
also make S arbitrarily large, which we can't. In this situation we'll
hit the S-limit first and our minimum length will be on that boundary
somewhere (possibly at an end point). Remember, the function is
continuous, so there's no weirdness going on. Well, not much anyway!
Hope this helps you. You may find it beneficial to work out what the
lengths will be along the S border, much as we did for the t border
(l' = l.|sin t| for S = - cot t) - this would speed up the
evaluations. Sorry, but I don't really feel like doing that just
now... it's time for lunch! |