3
$\begingroup$

I am building a piecewise function of two variables in 3D Cartesian space but, as currently written, it is utterly enormous. Is there a more compact way to implement it? (Context below!)

The Function

$$ h(θ, φ) := \\ \begin{cases} p_{FBase}\left(θ, φ \right) &: \sqrt{3} < f_{FBaseAft}(θ, φ)& ∧ &\sqrt{3} < f_{FBasePort}(θ, φ)& ∧ &\sqrt{3} < f_{FBaseStar}(θ, φ), \\ \\ p_{FAft}\left(θ, φ \right) &: \sqrt{3} < f_{FAftBase}(θ, φ)& ∧ &\sqrt{3} < f_{FAftPort}(θ, φ)& ∧ &\sqrt{3} < f_{FAftStar}(θ, φ), \\ p_{FAft}\left(θ, φ + \frac{2 π}{3}\right) &: \sqrt{3} < f_{FPortAft}(θ, φ)& ∧ &\sqrt{3} < f_{FPortBase}(θ, φ)& ∧ &\sqrt{3} < f_{FPortFore}(θ, φ), \\ p_{FAft}\left(θ, φ − \frac{2 π}{3}\right) &: \sqrt{3} < f_{FStarAft}(θ, φ)& ∧ &\sqrt{3} < f_{FStarBase}(θ, φ)& ∧ &\sqrt{3} < f_{FStarFore}(θ, φ), \\ \\ p_{VTop}\left(θ, φ \right) &: \sqrt{3} < f_{VTopFore}(θ, φ)& ∧ &\sqrt{3} < f_{VTopPort}(θ, φ)& ∧ &\sqrt{3} < f_{VTopStar}(θ, φ), \\ \\ p_{VFore}\left(θ, φ \right) &: \sqrt{3} < f_{VForePort}(θ, φ)& ∧ &\sqrt{3} < f_{VForeStar}(θ, φ)& ∧ &\sqrt{3} < f_{VForeTop}(θ, φ), \\ p_{VFore}\left(θ, φ − \frac{2 π}{3}\right) &: \sqrt{3} < f_{VPortAft}(θ, φ)& ∧ &\sqrt{3} < f_{VPortFore}(θ, φ)& ∧ &\sqrt{3} < f_{VPortTop}(θ, φ), \\ p_{VFore}\left(θ, φ + \frac{2 π}{3}\right) &: \sqrt{3} < f_{VStarAft}(θ, φ)& ∧ &\sqrt{3} < f_{VStarFore}(θ, φ)& ∧ &\sqrt{3} < f_{VStarTop}(θ, φ), \\ \\ p_{EAft}\left(θ, φ \right) &: f_{FAftBase}(θ, φ) ≤ \sqrt{3}& ∧ & f_{FBaseAft}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VPortAft}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VStarAft}(θ, φ) ≤ \sqrt{3}, \\ p_{EAft}\left(θ, φ + \frac{2 π}{3}\right) &: f_{FBasePort}(θ, φ) ≤ \sqrt{3}& ∧ &f_{FPortBase}(θ, φ) ≤ \sqrt{3}& ∧ &f_{VForePort}(θ, φ) ≤ \sqrt{3}& ∧ &f_{VPortFore}(θ, φ) ≤ \sqrt{3}, \\ p_{EAft}\left(θ, φ − \frac{2 π}{3}\right) &: f_{FBaseStar}(θ, φ) ≤ \sqrt{3}& ∧ &f_{FStarBase}(θ, φ) ≤ \sqrt{3}& ∧ &f_{VForeStar}(θ, φ) ≤ \sqrt{3}& ∧ &f_{VStarFore}(θ, φ) ≤ \sqrt{3}, \\ \\ p_{EFore}\left(θ, φ \right) &: f_{FPortFore}(θ, φ) ≤ \sqrt{3}& ∧ &f_{FStarFore}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VForeTop}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VTopFore}(θ, φ) ≤ \sqrt{3}, \\ p_{EFore}\left(θ, φ − \frac{2 π}{3}\right) &: f_{FAftPort}(θ, φ) ≤ \sqrt{3}& ∧ & f_{FPortAft}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VPortTop}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VTopPort}(θ, φ) ≤ \sqrt{3}, \\ p_{EFore}\left(θ, φ + \frac{2 π}{3}\right) &: f_{FAftStar}(θ, φ) ≤ \sqrt{3}& ∧ & f_{FStarAft}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VStarTop}(θ, φ) ≤ \sqrt{3}& ∧ & f_{VTopStar}(θ, φ) ≤ \sqrt{3} \end{cases} $$ where $$ \begin{align} p_{FBase}(θ, φ) &:= \frac{r − a}{2} ⋅ \left( \sqrt{\frac{3}{2}} ⋅ \cos(θ)\right) + r, \\ p_{FAft}(θ, φ) &:= \frac{r − a}{2} ⋅ \left(\sqrt{\frac{4}{3}} ⋅ \sin(θ) ⋅ \cos(φ) − \sqrt{\frac{1}{6}} ⋅ \cos(θ)\right) + r, \\ p_{FPort}(θ, φ) &:= p_{FAft}\left(θ, φ + \frac{2 π}{3}\right), \\ p_{FStar}(θ, φ) &:= p_{FAft}\left(θ, φ − \frac{2 π}{3}\right), \\ \\ p_{VTop}(θ, φ) &:= \frac{r − a}{2} ⋅ \left( \sqrt{\frac{3}{2}} ⋅ \cos(θ)\right) + a, \\ p_{VFore}(θ, φ) &:= \frac{r − a}{2} ⋅ \left(\sqrt{\frac{4}{3}} ⋅ \sin(θ) ⋅ \cos(φ) − \sqrt{\frac{1}{6}} ⋅ \cos(θ)\right) + a, \\ p_{VPort}(θ, φ) &:= p_{VFore}\left(θ, φ − \frac{2 π}{3}\right), \\ p_{VStar}(θ, φ) &:= p_{VFore}\left(θ, φ + \frac{2 π}{3}\right), \\ \\ p_{EAft}(θ, φ) &:= \frac{r − a}{2} ⋅ \left(\frac{6 ⋅ \sin(θ)^2 ⋅ \sin(φ)^2 − \left(3 − \left(\cos(θ) + \sqrt{2} ⋅ \cos(φ) ⋅ \sin(θ)\right)^2\right)}{8 ⋅ \sqrt{3} ⋅ \sin\left(\frac{π}{8}\right)^2 ⋅ \left(\sqrt{3} − \left(\cos(θ) + \sqrt{2} ⋅ \cos(φ) ⋅ \sin(θ)\right)\right)}\right) + \frac{r + a}{2}, \\ p_{EBPort}(θ, φ) &:= p_{EAft}\left(θ, φ + \frac{2 π}{3}\right), \\ p_{EBStar}(θ, φ) &:= p_{EAft}\left(θ, φ − \frac{2 π}{3}\right), \\ \\ p_{EFore}(θ, φ) &:= −\frac{r − a}{2} ⋅ \left(\frac{6 ⋅ \sin(θ)^2 ⋅ \sin(φ)^2 − \left(3 − \left(\cos(θ) + \sqrt{2} ⋅ \cos(φ) ⋅ \sin(θ)\right)^2\right)}{8 ⋅ \sqrt{3} ⋅ \sin\left(\frac{π}{8}\right)^2 ⋅ \left(\sqrt{3} + \left(\cos(θ) + \sqrt{2} ⋅ \cos(φ) ⋅ \sin(θ)\right)\right)}\right) + \frac{r + a}{2}, \\ p_{ETPort}(θ, φ) &:= p_{EFore}\left(θ, φ − \frac{2 π}{3}\right), \\ p_{ETStar}(θ, φ) &:= p_{EFore}\left(θ, φ + \frac{2 π}{3}\right), \end{align} $$ and where $$ \begin{align} f_{FBaseAft}(θ, φ) &:= \left(2 + 2 ⋅ \sqrt{2}\right) ⋅ \sin(θ) ⋅ \cos(φ) − \left(1 + 2 ⋅ \sqrt{2}\right) ⋅ \cos(θ), \\ f_{FBasePort}(θ, φ) &:= f_{FBaseAft}\left(θ, φ + \frac{2 π}{3}\right), \\ f_{FBaseStar}(θ, φ) &:= f_{FBaseAft}\left(θ, φ − \frac{2 π}{3}\right), \\ \\ f_{FAftBase}(θ, φ) &:= −\left(2 \right) ⋅ \sin(θ) ⋅ \cos(φ) + \left(3 + 2 ⋅ \sqrt{2}\right) ⋅ \cos(θ), \\ f_{FAftPort}(θ, φ) &:= f_{FPortAft}\left(θ, −φ − \frac{2 π}{3}\right), \\ f_{FAftStar}(θ, φ) &:= f_{FPortAft}\left(θ, φ − \frac{2 π}{3}\right), \\ \\ f_{FPortAft}(θ, φ) &:= \left(3 + 2 ⋅ \sqrt{2}\right) ⋅ \sin(θ) ⋅ \cos(φ) + \sqrt{3} ⋅ \sin(θ) ⋅ \sin(φ) − \cos(θ), \\ f_{FPortBase}(θ, φ) &:= f_{FAftBase}\left(θ, φ + \frac{2 π}{3}\right), \\ f_{FPortFore}(θ, φ) &:= f_{FPortAft}\left(θ, −φ + \frac{2 π}{3}\right), \\ \\ f_{FStarAft}(θ, φ) &:= f_{FPortAft}\left(θ, −φ \right), \\ f_{FStarBase}(θ, φ) &:= f_{FAftBase}\left(θ, φ − \frac{2 π}{3}\right), \\ f_{FStarFore}(θ, φ) &:= f_{FPortAft}\left(θ, φ + \frac{2 π}{3}\right), \\ \\ f_{VForePort}(θ, φ) &:= −f_{FPortAft}\left(θ, φ − \frac{2 π}{3}\right), \\ f_{VForeStar}(θ, φ) &:= −f_{FPortAft}\left(θ, −φ − \frac{2 π}{3}\right), \\ f_{VForeTop}(θ, φ) &:= −f_{FAftBase}\left(θ, φ \right), \\ \\ f_{VPortAft}(θ, φ) &:= −f_{FPortAft}\left(θ, φ + \frac{2 π}{3}\right), \\ f_{VPortFore}(θ, φ) &:= −f_{FPortAft}\left(θ, −φ \right), \\ f_{VPortTop}(θ, φ) &:= −f_{FAftBase}\left(θ, φ − \frac{2 π}{3}\right), \\ \\ f_{VStarAft}(θ, φ) &:= −f_{FPortAft}\left(θ, −φ + \frac{2 π}{3}\right), \\ f_{VStarFore}(θ, φ) &:= −f_{FPortAft}\left(θ, φ \right), \\ f_{VStarTop}(θ, φ) &:= −f_{FAftBase}\left(θ, φ + \frac{2 π}{3}\right), \\ \\ f_{VTopFore}(θ, φ) &:= −f_{FBaseAft}\left(θ, φ \right), \\ f_{VTopPort}(θ, φ) &:= −f_{FBaseAft}\left(θ, φ − \frac{2 π}{3}\right), \\ f_{VTopStar}(θ, φ) &:= −f_{FBaseAft}\left(θ, φ + \frac{2 π}{3}\right). \end{align} $$

Background

As part of a project I am working on, I am generating parametric regular shapes of constant width using support functions.

2D

The support function of a closed convex 2D curve describes the distances between the curve's supporting lines and the origin, where a supporting line is "a line that touches the boundary of the curve at one or more points but does not cross the interior of the curve". The Cartesian coordinates of a parametric curve can be defined in terms of the curve's support function $h(θ)$ and its derivative $h′(θ)$ as $$ x(θ) := \cos(θ) ⋅ h(θ) − \sin(θ) ⋅ h′(θ), \\ y(θ) := \sin(θ) ⋅ h(θ) + \cos(θ) ⋅ h′(θ). $$

Say we want a regular "triangle" of constant width $w$, maximum radius of curvature $r$, and minimum radius of curvature $a$, where $0 ≤ a ≤ r ≤ w$ and $w = r + a$. This "triangle" consists of two sets of three identical circular arcs: three larger arcs with radius $r$ for the edges, and three smaller arcs with radius $a$ for the vertices. In the extreme case where $a = 0$, the vertex arcs vanish into sharp corners; in the opposite extreme where $r = a$, all six arcs are identical and the curve becomes a perfect circle.

If we define the modulo function (which takes an input $x$ and adds or subtracts from it a divisor $d$ until the result is in the interval between zero, inclusive, and $d$, exclusive) as $$ \operatorname{mod}(x, d) := d ⋅ \left(\frac{x}{d} − \operatorname{floor}\left(\frac{x}{d}\right)\right), $$ define a helper function for conciseness $$ f(θ) := \operatorname{mod}\left(θ + \frac{π}{6}, \frac{2 π}{3}\right), $$ and give the support function the two-part piecewise definition $$ h(θ) := \begin{cases} \frac{r − a}{2} ⋅ \sec\left(\frac{π}{6}\right) ⋅ \cos\left(f(θ) − 1 ⋅ \frac{π}{6}\right) + a & : 0 ⋅ \frac{π}{3} ≤ f(θ) ≤ 1 ⋅ \frac{π}{3} \\ \frac{a − r}{2} ⋅ \sec\left(\frac{π}{6}\right) ⋅ \cos\left(f(θ) − 3 ⋅ \frac{π}{6}\right) + r & : 1 ⋅ \frac{π}{3} < f(θ) < 2 ⋅ \frac{π}{3} \end{cases} $$ the resulting curve will be "a regular Reuleaux triangle with initial width $r − a$, expanded to the width $w = r + a$". If $a = 0$, there is no expansion, and the resulting curve is simply a regular Reuleaux triangle of width $w = r$.

Animated GIF of a triangular curve of constant width.

3D

The support function of a closed convex 3D surface describes the distances between the surface's supporting planes and the origin, where a supporting plane is "a plane that touches the boundary of the surface at one or more points but does not cross the interior of the surface". The Cartesian coordinates of a parametric surface can be defined in terms of the surface's support function $h(θ, φ)$ and its derivatives $h_θ′(θ, φ)$ and $h_φ′(θ, φ)$ as $$ \begin{alignedat}{1} & x(θ, φ) = \sin(θ) ⋅ \cos(φ) & \, ⋅ \, h(θ, φ) + \cos(θ) ⋅ \cos(φ) & ⋅ h_θ'(θ, φ) − \frac{\sin(φ)}{\sin(θ)} ⋅ h_φ'(θ, φ), \\ & y(θ, φ) = \sin(θ) ⋅ \sin(φ) & \, ⋅ \, h(θ, φ) + \cos(θ) ⋅ \sin(φ) & ⋅ h_θ'(θ, φ) + \frac{\cos(φ)}{\sin(θ)} ⋅ h_φ'(θ, φ), \\ & z(θ, φ) = \cos(θ) & \, ⋅ \, h(θ, φ) − \sin(θ) & ⋅ h_θ'(θ, φ). \end{alignedat} $$

Instead of a regular "triangle" composed of two sets of three identical arcs (for a total of six curves), we have a regular "tetrahedron" composed of two sets of four identical sections of spheres plus a set of six identical sections of canal surfaces (for a total of 14 surface patches). Using the same variables $w$, $r$, and $a$ from the 2D case, we have: four larger sphere sections of radius $r$ for the faces, four smaller sphere sections of radius $a$ for the vertices, and six canal surface sections with radii varying between $a$ and $\frac{r − a}{2} ⋅ \sin\left(\frac{π}{8}\right)^2 + a$ for the edges.

Animated GIF of a tetrahedral surface of constant width.

In the 2D case, I was able to easily form an infinitely-repeating support function from only two piecewise pieces thanks to the modulo operation and the fact that the members of each arc-set are identical copies rotated around a single axis. However, I have not been able to figure out a way to do the same in the 3D case, as the symmetries and transformations between surface patches are more complicated, and the simplifications I've tried haven't worked across the entire input space.

Update

I managed to figure out a way to reduce the piecewise function from fourteen pieces to six pieces using two helper functions, the "modulo" function, and the "round" function (which outputs the integer that is closest to the input value). If we define $$ \begin{align} f(v) &:= \operatorname{mod}\left(π ⋅ \operatorname{round}\left(\frac{3}{π} ⋅ v\right), 2 π\right) + \operatorname{mod}\left(v + \frac{π}{6}, \frac{π}{3}\right) − π/6, \\ g(u, v) &:= \begin{cases} \operatorname{mod}\left(v , \frac{2 π}{3}\right) + \frac{2 π}{3} & : 0 < \operatorname{mod}(u, 2 π) < π \\ \operatorname{mod}\left(v + \frac{π}{3}, \frac{2 π}{3}\right) − \frac{ π}{3} & : \text{otherwise} \end{cases} \end{align} $$ the support function can be written as $$ h(θ, φ) := \\ \begin{cases} p_{FBase}(θ, φ ) &: \sqrt{3} < f_{FBaseAft}(θ, φ )& ∧ &\sqrt{3} < f_{FBasePort}(θ, φ )& ∧ &\sqrt{3} < f_{FBaseStar}(θ, φ ), \\ p_{FAft}(θ, f(φ)) &: \sqrt{3} < f_{FAftBase}(θ, f(φ))& ∧ &\sqrt{3} < f_{FAftPort}(θ, f(φ))& ∧ &\sqrt{3} < f_{FAftStar}(θ, f(φ)), \\ p_{VTop}(θ, φ ) &: \sqrt{3} < f_{VTopFore}(θ, φ )& ∧ &\sqrt{3} < f_{VTopPort}(θ, φ )& ∧ &\sqrt{3} < f_{VTopStar}(θ, φ ), \\ p_{VFore}(θ, f(φ)) &: \sqrt{3} < f_{VForePort}(θ, f(φ))& ∧ &\sqrt{3} < f_{VForeStar}(θ, f(φ))& ∧ &\sqrt{3} < f_{VForeTop}(θ, f(φ)), \\ \\ p_{EAft}(θ, g(θ, φ)) &: f_{FAftBase}(θ, g(θ, φ)) ≤ \sqrt{3}& ∧ & f_{FBaseAft}(θ, g(θ, φ)) ≤ \sqrt{3}& ∧ & f_{VPortAft}(θ, g(θ, φ)) ≤ \sqrt{3}& ∧ & f_{VStarAft}(θ, g(θ, φ)) ≤ \sqrt{3}, \\ p_{EFore}(θ, g(θ − π, φ)) &: f_{FPortFore}(θ, g(θ − π, φ)) ≤ \sqrt{3}& ∧ &f_{FStarFore}(θ, g(θ − π, φ)) ≤ \sqrt{3}& ∧ & f_{VForeTop}(θ, g(θ − π, φ)) ≤ \sqrt{3}& ∧ & f_{VTopFore}(θ, g(θ − π, φ)) ≤ \sqrt{3}. \\ \end{cases} $$

That's a significant improvement, but I'd like to find a way to condense the first four cases (two "face" patches and two "vertex" patches) all the way down into just one of each, if possible. It would also be great if there is a way to simplify the conditionals for each piece.

$\endgroup$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.