Consider a point picked uniformly at random from the area inside the shape with the coordinates (-2,0), (0,2), (2,0), (0,-2).
I need to find "the density function of the x coordinate".
The solution is for [-2,2]: $f(x)dx=P(X \in dx) = \frac{2*(2-|x|)dx}{4*(\frac{1}{2}*2*2)}=\frac{1}{4}(2-|x|)dx$.
So $f(x)=\frac{1}{4}(2-|x|)$ on $[-2,2]$ and otherwise $f(x)=0$.
It is $\frac{1}{4}(2+x)$ for $[-2,0]$ and $\frac{1}{4}(2-x)$ for $[0,2]$.
I found a formula for $U=\frac{X-a}{b-a}$ for $(a,b)$ for uniform distribution, but I don't think this is it, because then the solution to the question would be $\frac{X+2}{4}$ without $X$ being an absolute value. Plus it doesn't work with other similar questions.
Please help, it's a really weird exercise question on the textbook that doesn't give us any hint on how to solve it. I don't know how they got the $\frac{2*(2-|x|)dx}{4*(\frac{1}{2}*2*2)}$.
Also I have no idea how the solution's $f(x)$ means $f(x)=0$ when $x$ is not in $[-2,2]$
The formula $\frac{x-a}{b-a}$ is for the density of a uniform distribution on $[a,b]$. But the $x$-coordinate of your randomly chosen point from the shape is not uniform on $[-2, 2]$. The $x$-coordinate is more likely to be close to zero than it is to be close to $-2$ or $2$.
The density $f(x) \, dx$ can be approximated by finding $P(X \in dx)$, which is a shorthand for $P(x \le X < x + dx)$. Can you draw a picture of this sub-region inside your shape? It should look like a thin vertical strip with width $dx$ and height $2(2-|x|)$. The area of this region is approximately $(2-|x|) \, dx$. The area of the entire shape is $8$. Since $X$ is uniform on the shape, the probability is the area of the strip divided by the area of the shape. So, $P(x \le X < x + dx) = \frac{2(2 - |x|) \, dx}{8}$.