# Cumulative distribution function over a triangle

I have a random vector $(X,Y)$ with uniform distribution in a triangle $T$ with vertices $(0,0)$, $(1,0)$ and $(1,1)$ in $\mathbb{R}^2$, and I'm trying to find the cumulative distribution function $F(x,y)$.

Clearly for the probability density function I have:

$$f(x,y)=\frac{1}{\text{area(T)}}=\frac{1}{1/2}=2$$

Is it also clear that $F(x,y)=0$ for $y\leq 0$ and for $x\leq 0$. Also, $F(x,y)=1$ for all $x,y$ with $x,y\geq 1$.

Now, the solution for $(x,y)\in T$ is supposed to be $F(x,y)=2xy-y^2$. I have trouble understanding this.

My first attempt is, using the usual definition of CDF, is

$$F(x,y)=\int_0^y \int_0^x f(u,v)dudv=\cdots=\color{red}{2xy}$$

which is different with the given solution. Toying with the limits of integration I get the solution making:

$$F(x,y)=\int_0^y \int_v^x f(u,v)dudv=\cdots=2xy-y^2$$

But I don't see why it should work.

Furthermore, this way the result remains correct for $x\geq 1$, $0\leq y\leq 1$,

$$F(x,y)=\int_0^y \int_v^1 f(u,v)dudv=\cdots=2y-y^2$$

But for $0\leq x\leq 1$, $y\geq x$ the correct solution is $x^2$, but I get:

$$F(x,y)=\int_0^1 \int_v^x f(u,v)dudv=\cdots=\color{red}{2x-1}$$

Fix a point $(x,y)$ in triangle $T$, and let $S$ be the region defined by
$$S = \{(X,Y) \in T \mid X \le x \text{ and } Y \le y\}$$
Note that $S$ is a trapezoid with height $y$ and base lengths $x$ and $x-y$. Then
If you prefer integration, then, since the horizontal slice of the trapezoid at height $v$ extends from the point $(v,v)$ to the point $(x,v)$, the corresponding double integral is the one you noted, namely $$F(x,y)=\int_0^y \int_v^x f(u,v)\;du\,dv$$ where $f(u,v) = 2$.