Is there a way to simplify $\Big|\;|x+y|+|x-y|+z\;\Big|+\Big|\;|x+y|+|x-y|-z\;\Big|=r$? Is there a way to simplify this
$$\Big|\;|x+y|+|x-y|+z\;\Big|+\Big|\;|x+y|+|x-y|-z\;\Big|=r$$
so that it turns out something like:
$$|ax+by+cz|+|dx+ey+fz|+\cdots=ur$$
where $a$, $b$, $c$, ..., $u$ is a constant?
Or is there a way to at least simplify it so that there is only 1 layer deep of abs() function?
Side notes: This is for a fast collision detection of a AABB and a ray. If you graph the formula above (with r related to the size of the box), it will show a 3d box. I have used the same method to make a fast 2d box collision detection but have no idea how to make it 3d as I was stuck on this step...
Edit: Yes, I know I can use max(a,b,c) =ur to discribe this. And I'm turning it around so that I can find all the "break" points (should be 8 of them??) of this function:
$$y=\Big|\;|P_x+P_y|+|P_x-P_y|+P_z\;\Big|+\Big|\;|P_x+P_y|+|P_x-P_y|-P_z\;\Big|$$
$$where$$
$$P=(V_1+(V_2-V_1)x)$$
(V1 and V2 is a given 3D vector.)
so that I can calculate quickly what x has to be so that the function above return the smallest value possible.
(Also, everything is real number. Don't want to deal with complex number today...)
Actually... should I just ask what the break point is...Errrr... Sorry. New user here.
 A: I would suggest working through different cases -
i) For $x \ge y \ge 0, x \ge \frac{|z|}{2},\Big|\;|x+y|+|x-y|+z\;\Big|+\Big|\;|x+y|+|x-y|-z\;\Big|=r$ becomes (where $r \ge 0$)
$2x + z + 2x - z = r, x = \frac{r}{4}$
ii) For $x \ge y \ge 0, x \lt \frac{|z|}{2}$,
$2x + z - (2x - z) = r, z = \pm \frac{r}{2}$
iii) For $y \ge x \ge 0, y \ge \frac{|z|}{2}$, $4y = r, y = \frac{r}{4}$
iv) For $y \ge x \ge 0, y \lt \frac{|z|}{2}$, $2z = r, z = \pm \frac{r}{2}$
Checking all other cases, the final set of equations become -
i) For $|x| \ge |y|, |x| \ge \frac{|z|}{2}, x = \pm \frac{r}{4}$
ii) For $|x| \ge |y|, |x| \lt \frac{|z|}{2}$, $z = \pm \frac{r}{2}$
iii) For $|y| \ge |x|, y \ge \frac{|z|}{2}$, $y = \pm \frac{r}{4}$
iv) For $|y| \ge |x|, |y| \lt \frac{|z|}{2}$, $z = \pm \frac{r}{2}$
So you get $6$ planes, $x = \pm \frac{r}{4}, y = \pm \frac{r}{4}, z = \pm \frac{r}{2}$. It is obvious what the shape of the bound region would be.
A: There is a way to remove both layers of absolute values, but I wouldn't consider it a simplification since they just get replaced by two layers of the $\max(x,y)$ function.
The maximum of $x$ and $y$ is given by the formula $\max(x,y)=\frac{x+y+|x-y|}{2}$, so we have
$$2\max(x,y)+2\max(x,-y)=x+y+|x-y|+x-y+|x+y|=2x+|x-y|+|x+y|\Rightarrow\\
|x+y|+|x-y|=2(\max(x,y)+\max(x,-y)-x),$$
so now the term $||x+y|-|x-y|\pm z|$ can be replaced with
$$|\max(x,y)+max(x,-y)-x\pm\frac 12z|$$
and the right-hand side has to be divided by $2$.
To remove the second layer of the absolute value, let $a=\max(x,y)+max(x,-y)-x$. Now we have
$$|a+\frac 12z|+|a-\frac12 z|,$$
so the same as above can be applied with $\max(a,\frac12 z)$ and $\max(a,-\frac 12 z)$.
A: I claim that for all $a, b \in \mathbb{R}$, we have
$$\frac{|a+b| + |a-b|}{2} = \max(|a|,|b|)$$
To see that, let's denote $f(a,b) = \frac{|a+b| + |a-b|}{2}$, and separate 3 cases : $a < -|b|$, $-|b| \le a \le |b|$ and $a > |b|$ :

*

*If $a < - |b|$, then $a+|b| < 0$ and $a - |b|< -2|b| < 0$ so $f(a,b) = f(a,|b|) =  \frac{-(a+|b|) - a + |b|}{2} = -a = \max(|a|,|b|)$.


*If $-|b| \le a \le |b|$, then $a + |b| \ge 0$ and $a - |b|\le 0$ so $f(a,b) = f(a,|b|) =  \frac{(a+|b|) - a + |b|}{2} = |b| = \max(|a|,|b|)$.


*If $|b| \le a$, then $a + |b| \ge 2|b|\ge 0$ and $a - |b| \ge 0$ so $f(a,b) = \frac{(a+|b|) + a-|b|}{2} = a = \max(|a|,|b|)$
Knowing that, your equation becomes :
$$2 \max(2\max(|x|,|y|), |z|) = r$$
Or in other words
$$\max(\, 2|x|, \ 2|y|,\ |z| \,) = \frac{r}{2}$$
So I think the equation describes a cuboid of lengths $\frac{r}{2}$, $\frac{r}{2}$ and $r$ (along the $x$, $y$ and $z$ axis respectively) centered at the origin.
