3

What is the area of the following region: $|x-ay| \le c$ for $0 \le x \le 1$ and $0 \le y \le 1$. Assume $c>0$.

We can also assume $|a|>1$ since it will not change the essence of the problem.

Progress

We get a strip embedded inside of the square. I was wondering if there is a clean way to approach this, since there are many different sub cases.

Boby
  • 5,985
  • As a first step: rewrite $|x-ay|\leq c$ without the absolute. – lemon Aug 17 '14 at 17:54
  • So, we get a strip embedded inside of the square. I knew that. I was wondering if there is a clean way to approach this, since there are many different sub cases. – Boby Aug 17 '14 at 17:56
  • It's not terribly obvious to me either. Maybe try flipping it around: How much of the unit square is not within the strip? I think that only requires finding the area of triangular corners. – Semiclassical Aug 17 '14 at 17:57
  • You can also get a trapezoid, right? – Boby Aug 17 '14 at 17:58
  • @user63050 Not only a trapezoid, you can even get an irregular pentagon. For example, let $a=\frac32$ and $c=\frac12$. – David H Aug 17 '14 at 18:04
  • One question mark is sufficient to indicate that a sentence is a question. –  Aug 17 '14 at 18:09

2 Answers2

1

EDIT: This approach leads nowhere.

Let $S = \{(x,y) \in [0,1]^2 : |x-ay|\leq c\}$. Consider the linear bijective map $$f(x,y) = (x-ay,y) = (u,v)$$ Then the $f(S) = \{(u,v) \in [-a,1] \times [0,1] : |u| \leq c\} =: S_0$.

EDIT: The following statement is wrong.

The area $V(S_0) = 1 \cdot (\min \{c,1\}-\max\{-c,-a\})$ (rectangle), since $c>0$

Note that $S = f^{-1}(S_0)$ thus $$V(S) = |\det f^{-1}| V(S_0)= |\det f|^{-1} V(S_0) = 1\cdot V(S_0) = \min \{c,1\}-\max\{-c,-a\},$$ because $$\det f = \left| \begin{pmatrix} 1 & -a \\ 0 & 1 \end{pmatrix}\right| = 1.$$

I hope this is correct.

flawr
  • 16,533
  • 5
  • 41
  • 66
  • This approach seems promising? Could you please explain why your definition of $f(S)$ is the way it is? Also, $u$ can be negative, right? and you assume that it's positive, right? – Boby Aug 17 '14 at 21:11
  • Yes you are right, $u$ can be negative, I did not think of that. $f(S)$ is not a definition but a result of applying $f$ to $S$. – flawr Aug 17 '14 at 21:14
  • Would this change by much if we include $u$ to be negative?? – Boby Aug 17 '14 at 21:17
  • I updated it now. Of course $S_0$ changed, and of course $V(S_0)$ so here you go. – flawr Aug 17 '14 at 21:20
  • Thank you very much. Could explain a little about $V(S)$. This formula that you are using for the volume where does it come from? Or rather what it is it called? – Boby Aug 17 '14 at 21:22
  • $f(S)$ is basically a rectangle, and $S$ a linearly transformed rectangle, that means it remains a parallelogram but can be rotated and squeezed. This 'formula' with $V$ can be viewed as variable transformation https://en.wikipedia.org/wiki/Integration_by_substitution#Substitution_for_multiple_variables (which is a bit a overpowered) but there is also a theorem in linear algebra that is basically a special case of the mentioned one just for linear transformations, I'll see if i can find it. https://en.wikipedia.org/wiki/Determinant – flawr Aug 17 '14 at 21:30
  • The idea is basically that the determinant of the map shows how mucht the volume changes. This is easy to understand when you know that the determinant is the product of all eigenvalues. So if one eigenvalue changed, the volume changes only in one dimension. If two eigenvalues lets say are doubled, the volume increases in two dimensions in this case by factor 2x2=4. Also see https://en.wikipedia.org/wiki/Parallelepiped and you can google 'Volume change under linear Transformation', I will let you know when I find a good resource. – flawr Aug 17 '14 at 21:33
  • Suppose, we try an example $|x-y| \le 0.5$. So, $a=1$ and $c=0.5$. If you where to compute the area of the strip we get $1-2\Delta$. Where $\Delta$ is the area of the upper triangle. So we get an area of Area=$1-0.5*0.5=0.75$. With your approach we get that the area is $ \min(0.5,1)-\max(-0.5,-1)=1$. It seems like something is missing? Who is wrong? – Boby Aug 17 '14 at 21:40
  • I see your point but I cannot spot the error in my solution yet. I calculate $f(S)$ wrong, but I do not see where the error lies. – flawr Aug 17 '14 at 21:52
  • Ok I think my approach will not work here. The condition $(x,y) \in [0,1]^2$ maps to $(u+v,v) \in [0,1]^2$ and we have the same problem again. I am sorry, my approach was no help here... – flawr Aug 17 '14 at 22:05
  • Sorry, I didn't understand. What is wrong with approach? Is it the mapping? – Boby Aug 17 '14 at 22:45
1

All sub cases. Consider the strip embedded inside the square, as mentioned in the question, a bit modified though (without loss of generality): $$ \left|\, \cos(\phi) x + \sin(\phi) y\, \right| < c \quad \mbox{with} \; c > 0 \; , \; 0 \le \phi < \pi \quad \mbox{for} \; 0 \le x \le 1 \; , \; 0 \le y \le 1 $$ The vertices of the square are $\;(x_k,y_k) = \left\{(0,0),(1,0),(0,1),(1,1)\right\} , \; k=0,1,2,3\;$ . Each of the vertices can be, in principle

  • $(0)$ below the strip: $\;\cos(\phi) x_k + \sin(\phi) y_k \le -c$
  • $(1)$ inside the strip: $\;-c < \cos(\phi) x_k + \sin(\phi) y_k < +c$
  • $(2)$ above the strip: $\;+c \le \cos(\phi) x_k + \sin(\phi) y_k$
With exception of $(x_0,y_0) = (0,0)$ ; this vertex is always inside the strip. (You're lucky, otherwise you had to distinguish $3^4 = 81$ cases to begin with.) Now there are $3^3 = 27$ sub cases, in principle. They can be conveniently enumerated in a base $3$ number system . For example $210$ means that vertex $(1,0)$ is below the strip, vertex $(0,1)$ is inside the strip and vertex $(1,1)$ is above the strip: the number is read from the right to the left, i.e. towards the most significant digit (as usual). Because of the restriction $0 \le \phi < \pi$ only the cases $\;000 \cdots 111\;$ have to be considered. The other cases are a mirror of these if $0 \le \phi < 2\pi$ is allowed eventually. With one noteworthy exception, though, namely $010 \not \equiv 212$ ($\color{red}{red}$) . So here comes: $$ \begin{matrix} 000 & 001 & 002 & \color{red}{010} & 011 & 012 & 020 & 021 & 022 & 100 & 101 & 102 & 110 & 111 \\ 222 & 221 & 220 & \color{red}{212} & 211 & 210 & 202 & 201 & 200 & 122 & 121 & 120 & 112 & \\ & & & & & NOP & & NOP & NOP & NOP & & & & \end{matrix} $$ A picture says more than a thousand words:
enter image description here
It is seen that there are at most 11 sub cases that must be taken into account.

Area of polygon. Though at the moment we have only an impression of what the polygons look like, the areas of them have to be calculated, in the end. enter image description here

So it's useful anyway to have a general method for doing just that. What we can do is to draw ($\color{red}{red}$) lines from the origin $(0)$ to the vertices of the polygon (six in our case) and sum up the areas of the (six) triangles $(0,1,2),(0,2,3),(0,3,4),(0,4,5),(0,5,6),(0,6,1)$ : see figure at the bottom. The figure at the top shows how the area of just one triangle is calculated, by using a determinant: $$ \mbox{area}\,\Delta = \frac{1}{2} det\begin{bmatrix}(x_2-x_1) & (y_2-y_1)\\(x_3-x_1) & (y_3-y_1)\end{bmatrix} $$ Note that, in general, the triangle areas thus calculated can be positive as well as negative. And the latter is essential.
To be continued for the coordinates of the polygons, in anti-clockwise order.

Clipping problem. Usually a polygon (strip) is clipped against the square. But in our case, the square is clipped against a strip. Once the ideas are clear, the algebra involved is very elementary. Hoping that the program below is more or less self-documentary:

program Q901259;
type point = record x,y : double; end; polygon = array of point;
function Area(round : polygon) : double; { Area of polygon } var k,L : integer; Det,Opp : double; p,q : point; begin Opp := 0; L := Length(round); if L > 0 then begin q := round[L-1]; for k := 0 to L-1 do begin p := q; q := round[k]; Det := (p.xq.y - q.xp.y); Opp := Opp + Det; end; end; Area := Opp/2; end;
function let(x,y : double) : point; var P : point; begin P.x := x; P.y := y; let := P; end;
function x_is_0(c,p : double) : point; begin x_is_0 := let(0,c/sin(p)); end;
function x_is_1(c,p : double) : point; begin x_is_1 := let(1,(c-cos(p))/sin(p)); end;
function y_is_0(c,p : double) : point; begin y_is_0 := let(c/cos(p),0); end;
function y_is_1(c,p : double) : point; begin y_is_1 := let((c-sin(p))/cos(p),1); end;
function Calculate(p,c : double) : double; { Calculate area of strip inside square xcos(p) + ysin(p) = +/- c : strip } const choice : array[0..26] of integer = (0,1,2,3,4,-1,5,-1,-1,-1,6,7,8,9 ,8,7,6,-1,-1,-1,5,-1,4,10,2,1,0); var k,number,digit : integer; x,y : double; poly : polygon; begin SetLength(poly,1); poly[0] := let(0,0); number := 0;
{Ternary number system } for k := 2 downto 0 do begin x := (k+1) mod 2; y := (k+1) div 2; digit := 1; if cos(p)*x+sin(p)*y < -c then digit := 0; if cos(p)*x+sin(p)*y > +c then digit := 2; number := number*3 + digit; end;
{All sub cases } case choice[number] of 0 : begin SetLength(poly,3); poly[1] := y_is_0(+c,p); poly[2] := x_is_0(+c,p); end; 1 : begin SetLength(poly,4); poly[1] := let(1,0); poly[2] := x_is_1(+c,p); poly[3] := x_is_0(+c,p); end; 2 : begin SetLength(poly,5); poly[1] := y_is_0(-c,p); poly[2] := x_is_1(-c,p); poly[3] := x_is_1(+c,p); poly[4] := x_is_0(+c,p); end; 3 : begin SetLength(poly,4); poly[1] := y_is_0(-c,p); poly[2] := y_is_1(-c,p); poly[3] := let(0,1); end; 4 : begin SetLength(poly,5); poly[1] := let(1,0); poly[2] := x_is_1(+c,p); poly[3] := y_is_1(+c,p); poly[4] := let(0,1); end; 5 : begin SetLength(poly,5); poly[1] := y_is_0(-c,p); poly[2] := y_is_1(-c,p); poly[3] := y_is_1(+c,p); poly[4] := x_is_0(+c,p); end; 6 : begin SetLength(poly,5); poly[1] := let(1,0); poly[2] := let(1,1); poly[3] := y_is_1(+c,p); poly[4] := x_is_0(+c,p); end; 7 : begin SetLength(poly,6); poly[1] := y_is_0(-c,p); poly[2] := x_is_1(-c,p); poly[3] := let(1,1); poly[4] := y_is_1(+c,p); poly[5] := x_is_0(+c,p); end; 8 : begin SetLength(poly,5); poly[1] := y_is_0(-c,p); poly[2] := x_is_1(-c,p); poly[3] := let(1,1); poly[4] := let(0,1); end; 9 : begin SetLength(poly,4); poly[1] := let(1,0); poly[2] := let(1,1); poly[3] := let(0,1); end; 10 : begin SetLength(poly,4); poly[1] := y_is_0(+c,p); poly[2] := y_is_1(+c,p); poly[3] := let(0,1); end; end; Calculate := Area(poly); end;
begin Random; Random; { Test } while true do begin Writeln(Calculate(Random*Pi,Random)); Readln; end; end.
But: is it possible to have a solution without all the sub case jazz? The answer is affirmative; that's how I actually tested the correctness of the above program. Any area can be simply determined by pixel counting (not necessarily in a "real" picture). Advantage: quick and dirty. Disadvantage: less exact than the sub case method.
Han de Bruijn
  • 17,070
  • Wow. Thank you. Very impressive answer. Could explain how your transformation is with out loss of generality? Also, if I understand correctly your solution is numerical and there is no close form solution for the formula of the area, right? – Boby Aug 28 '14 at 17:21
  • Are you familiar with the normal form of a line? We can scale the coefficients of a given linear equation by any (non-zero) constant and the result will be unchanged. So if $ax+by=c$ then we can divide the equation by $\sqrt{a^2+b^2}$ to get $a/\sqrt{a^2+b^2}\cdot x + b/\sqrt{a^2+b^2}\cdot y = c/\sqrt{a^2+b^2}$ . Now put $a/\sqrt{a^2+b^2} = \cos(\phi)$ and $b/\sqrt{a^2+b^2} = \sin(\phi)$ (: draw a rectangular triangle with sides $a,b$ and hypotenusa $\sqrt{a^2+b^2}$ to explain). The result is an equivalent equation $;\cos(\phi)x+\sin(\phi)y=p$ . – Han de Bruijn Aug 29 '14 at 11:08
  • When comparing your formula $|x-ay| \le c$ with the normed one $|\cos(\phi)x+\sin(\phi)y| \le c$ , we see that $|x - \left[-\tan(\phi)\right].y| \le c/\cos(\phi)$ . Here $\phi$ is the angle of the normal perpendicular to the strip with the x-axis. The slope of the line itself is $\theta = \phi-\pi/2$ . Hence, with "your" $c$ : $|y-\tan(\theta)x| \le c$ . Meaning that $|\tan(\theta)| < 1$ or $|\theta| < \pi/4$ . The range for $\phi$ in my answer is somewhat larger, namely $0 \le \phi < \pi$ , hence $|\theta| < \pi/2$ . Thus there rather is some gain of generality (twice) instead of a loss. – Han de Bruijn Aug 29 '14 at 11:28
  • The fact that I've coded everything as a Pascal program does only mean that I can't find a sub-language in common mathematics to formulate these results properly. So the programming does not at all mean that the result is numerical. In fact, the whole treatment is meant to be exact. Admittedly, there is not one closed formula for the area; rather there are eleven "closed" formulas. (What does "closed" mean in modern times anyway ?) – Han de Bruijn Aug 29 '14 at 11:48