Google Answers Logo
View Question
 
Q: to obtain minimum length of a line segment under shear transformation ( No Answer,   5 Comments )
Question  
Subject: to obtain minimum length of a line segment under shear transformation
Category: Science > Math
Asked by: rich8rd-ga
List Price: $25.00
Posted: 29 Nov 2005 21:03 PST
Expires: 29 Dec 2005 21:03 PST
Question ID: 599295
suppose that an image is pre-processed to extract all the line
segments using edge detection and line segmentation, so you've got a
set of line segments. Each line has 4 parameters: center point (x, y),
angle (theta) and length (l). Theta is between 0 and PI. Let the
"shear" factor to be SH. Now shear transformation will transform each
x coordinate by (SH * y), so the new x coordinate after shear is (x +
SH*y), and y coordinate is unchanged. Shear transformation also affect
on the line angle and length. I am now only interested in the impact
on line segment length.

With my calculation, I found that length related to SH follows this equation:

L (new) = L(old) * SQRT(1+2sin(theta)cos(theta)*SH +
sin(theta)sin(theta)*SQUARE(SH))

Now each line at this point can have a range of theta, (theta max) and
(theta min) is known. Each line also have a range of length, (l min)
and (l max) is known. Further, the Shear factor can also have a range
of values, bounded by (SH min) and (SH max). So all three variables in
the equation above can change. I want to know, given these conditions,
what is the minimum and maximum length of l. (I?m more interested in
the minimum length).

Thanks in advance.

Richard
Answer  
There is no answer at this time.

Comments  
Subject: Re: to obtain minimum length of a line segment under shear transformation
From: berkeleychocolate-ga on 01 Dec 2005 12:55 PST
 
Here's an elegant way to look at this problem. Let A and B be the
endpoints of the first segment and C=the shear applied to A, D=the
shear applied to B. So segment AB has length L(old) and CD has length
L(new). Observe that point C is directly above A and D is directly
above B. Let E be the fourth parallelogram point to ABC. Then
obviously CE has length L(old), and it is easy to show that segment DE
is the product of the three numbers SH, L(old), sin(theta). So all the
answers are contained in the triangle CDE. Clearly the bigger or
smaller each of these factors is, the bigger of smaller will be
L(new). So the smallest value of L(new) is attained at the smallest
values of the three factors.
Subject: Re: to obtain minimum length of a line segment under shear transformation
From: rich8rd-ga on 01 Dec 2005 18:11 PST
 
Hi berkeleychocolate, thanks very much for the comment. You said that
C is directly above A and D is directly above B, but C and D are
actually horizontal to A and B. but this shouldn't matter. Following
your method, as DE=SH*L(old)*Sin(theta) and CE=L(old), using triangle
formula square(a) = square(b) + square(c) - 2ab*cos(theta), CD is
therefore still equal to my original L(new) length which is  L(old) *
SQRT(1+2sin(theta)cos(theta)*SH +
sin(theta)sin(theta)*SQUARE(SH)), which i think isn't monotonically
increasing or decreasing from the graph it generates.

If i understand you wrongly please clarify. Thanks again.
Subject: Re: to obtain minimum length of a line segment under shear transformation
From: manuka-ga on 01 Dec 2005 20:58 PST
 
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!
Subject: Re: to obtain minimum length of a line segment under shear transformation
From: berkeleychocolate-ga on 03 Dec 2005 16:00 PST
 
Sorry about confusing "up" with "right". I presumed that theta was
less than 90 degrees, and then the statement is clear from the
picture. We can assume theta is less than 180 degrees by picking the
endpoint A appropriately. I am assuming the shear SH is positive.
Let's look at theta in the second quadrant. The factor sqrt(1 +
2*SH*sin(theta)*cos(theta) +sh^2*sin(theta)^2), which you correctly
wrote is the length of the vector (cos(theta),sin(theta)) +
(SH*sin(theta),0). This means go a horizontal distance SH*sin(theta)
from the point on the unit circle. You can represent this as
x=cos(theta) + SH*sin(theta), y=sin(theta). Or x=-sqrt(1-y^2) +SH*y
since cos(theta)<0 in the second quadrant. Let S=x^2+y^2. Then S turns
out to equal 1 +(SH*y)^2 -2*SH*y*sqrt(1-y^2). Remember 0<=y<=1.
Calculus gives a minimum where SH*y=(1-2y^2)/sqrt(1-y^2). This reduces
to a quadratic in y^2, which can be easily solved. Hope this is
helpful.
Subject: Re: to obtain minimum length of a line segment under shear transformation
From: rich8rd-ga on 03 Dec 2005 20:06 PST
 
Thanks manuka, your comment cleared things up for me quite a bit. if
you post it in answers i'll gladly give you the credit (or whatever
google do to get you paid). And thanks berkeleychocolate for
clarifying. the solution seems much more complicated than i was hoped.
originally i was trying to do scaling in Y and shearing on a line set
and find parameter ranges. it now seems that i should do shearing
first and scaling in y direction, which would avoid much of the hassle
in finding minimum and maximum line length.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy