Determine whether a vector intersects the up or down unit vector I wrote an if statement that checks if an iteratively altered vector "crosses" the up vector (0,1,0) or the down vector (0,-1,0).

if ((lastDiff.x() &gt; 0 &amp;&amp; diff.x() &lt; 0 &amp;&amp; lastDiff.z() &gt;= 0 &amp;&amp; diff.z() &lt;= 0) || 
    (lastDiff.x() &lt; 0 &amp;&amp; diff.x() &gt; 0 &amp;&amp; lastDiff.z() &gt;= 0 &amp;&amp; diff.z() &lt;= 0) ||
    (lastDiff.x() &gt; 0 &amp;&amp; diff.x() &lt; 0 &amp;&amp; lastDiff.z() &lt;= 0 &amp;&amp; diff.z() &gt;= 0) ||
    (lastDiff.x() &lt; 0 &amp;&amp; diff.x() &gt; 0 &amp;&amp; lastDiff.z() &lt;= 0 &amp;&amp; diff.z() &gt;= 0) ||
    (lastDiff.z() &gt; 0 &amp;&amp; diff.z() &lt; 0 &amp;&amp; lastDiff.x() &gt;= 0 &amp;&amp; diff.x() &lt;= 0) ||
    (lastDiff.z() &lt; 0 &amp;&amp; diff.z() &gt; 0 &amp;&amp; lastDiff.x() &gt;= 0 &amp;&amp; diff.x() &lt;= 0) ||
    (lastDiff.z() &gt; 0 &amp;&amp; diff.z() &lt; 0 &amp;&amp; lastDiff.x() &lt;= 0 &amp;&amp; diff.x() &gt;= 0) ||
    (lastDiff.z() &lt; 0 &amp;&amp; diff.z() &gt; 0 &amp;&amp; lastDiff.x() &lt;= 0 &amp;&amp; diff.x() &gt;= 0))


I feel like there is a simpler or better way to implement this if guard but I can't find it.
You have four groups of repeating conditions:

bool crossX = (lastDiff.x() &lt; 0 &amp;&amp; diff.x() &gt; 0) || (lastDiff.x() &gt; 0 &amp;&amp; diff.x() &lt; 0);
bool crossZ = (lastDiff.z() &lt; 0 &amp;&amp; diff.z() &gt; 0) || (lastDiff.z() &gt; 0 &amp;&amp; diff.z() &lt; 0);
bool crossTouchX = (lastDiff.x() &lt;= 0 &amp;&amp; diff.x() &gt;= 0) || (lastDiff.x() &gt;= 0 &amp;&amp; diff.x() &lt;= 0);
bool crossTouchZ = (lastDiff.z() &lt;= 0 &amp;&amp; diff.z() &gt;= 0) || (lastDiff.z() &gt;= 0 &amp;&amp; diff.z() &lt;= 0);


Using these the original condition can be simplified to:

if ((crossX &amp;&amp; crossTouchZ) || (crossZ &amp;&amp; crossTouchX))
{
    // do stuff
}