minimum value of dot product with planar vector and planar axes

38 Views Asked by At

I am writing some code and want to select a calculation to do based on "how much" of a direction vector is in the X and Z axis (which are the planar axes in Unity). If more of the direction vector is along the X axis, I want to compute Y(X); but if more of the vector is along the Z axis, I want to compute Y(Z). I am hopeful that doing this will avoid undefined behavior when the curve is entirely (or almost entirely) parallel to the XY plane or ZY plane. Here is what I wrote:

// Vector3.right is the x-axis
if (Mathf.Abs(Vector3.Dot(direction,Vector3.right)) >= Mathf.Sqrt(2f) )
{
    //Calculate Y(x)
}
else
{
    //Calculate Y(z)
}

Is this logical? In this situation, would the dot product always be greater than or equal to $\sqrt{2}$ with respect to either the X or Z axis? That is the question.

1

There are 1 best solutions below

3
On BEST ANSWER

In Mathematica:

If[Abs[#[[1]]]>Abs[#[[2]]],f[#],g[#]]&

You simply look at the $x$ component (#[[1]]) and the $y$ (#[[2]]) component of the vector and see which is larger.