# Generating a Consistently Oriented Tangent Space

This webpage is a demo made for a presentation entitled Combing Hair and Sampling Directions [slides], which I presented at a Christmas workshop in December 2014.

The demo was updated March 2017 to include newly published observations [Duff et al. 2017; Max 2017].

## The Hairy Ball Theorem

An even-dimensional sphere does not possess any continuously differentiable field of unit tangent vectors. [Milnor 1978]

A function that given a unit direction vector generates a perpendicular unit vector must have discontinuity lines or at least one singular point.

If we try to comb a hairy ball flat, there will always be at least one tuft.

## Combing a Hairy Ball

By Jeppe Revall Frisvad (based on a paper and a blog posting)

Mouse control: orbit - left button, dolly - middle button, pan - right button.
Touchscreen control: orbit - one finger, dolly - two finger pinch, pan - two finger drag. [properly supported in Chrome]

Drawing the hair strands along the vector $\vec{t} = (t_x, t_y, t_z)$ which is generated using the surface normal $\vec{n} = (n_x, n_y, n_z)$.

 Please use a browser that supports HTML5 canvas. $\vec{t} = \vec{n}$ \begin{eqnarray} \mathbf{t} & = & \left\{\begin{array}{lcl}(0, 1, 0) - n_y \vec{n} & , & \textrm{for $n_x > 0.9$} \\ (1, 0, 0) - n_x \vec{n} & , & \textrm{otherwise}\end{array}\right. \$1em] \vec{t} & = & \frac{\mathbf{t}}{\|\mathbf{t}\|} \end{eqnarray} \begin{eqnarray} \mathbf{t} & = & \left\{\begin{array}{lcl}(0, -n_z, n_y) & , & \textrm{for |n_x| \leq |n_y| and |n_x| \leq |n_z|} \\ (-n_z, 0, n_x) & , & \textrm{for |n_y| \leq |n_x| and |n_y| \leq |n_z|} \\ (-n_y, n_x, 0) & , & \textrm{otherwise}\end{array}\right. \\[1em] \vec{t} & = & \frac{\mathbf{t}}{\|\mathbf{t}\|} \end{eqnarray} \begin{eqnarray} \mathbf{t} & = & \left\{\begin{array}{lcl}(-n_y, n_x, 0) & , & \textrm{for |n_x| > |n_z|} \\ (0, -n_z, n_y) & , & \textrm{otherwise}\end{array}\right. \\[1em] \vec{t} & = & \frac{\mathbf{t}}{\|\mathbf{t}\|} \end{eqnarray} \[ \vec{t} = \left(1 - \frac{n_x^2}{1 + |n_z|}, -\frac{n_xn_y}{1 + |n_z|}, -n_x\,\mathrm{sgn}(n_z)\right) \, .$ $\vec{t} = \left\{\begin{array}{lcl}(0, -1, 0) & , & \textrm{for n_z < -0.9999805689 [Max 2017]} \\[1ex] \displaystyle\left(1-\frac{n_x^2}{1 + n_z}, -\frac{n_xn_y}{1 + n_z}, -n_x\right) & , & \textrm{otherwise}\end{array}\right.$

## References

• Milnor, J. Analytic Proofs of the "Hairy Ball Theorem" and the Brouwer Fixed Point Theorem. The American Mathematical Monthly 85(7), pp. 521-524, 1978.
• Hughes, J. F., and Möller, T. Building an Orthonormal Basis from a Unit Vector. Journal of Graphics Tools 4(4), pp. 33-35, 1999.
• Parker, S. G., Bigler, J., Dietrich, A., Friedrich, H., Hoberock, J., Luebke, D., McAllister, D., McGuire, M., Morley, K., Robison, A., and Stich, M. OptiX: A general purpose ray tracing engine. ACM Transactions on Graphics (Proceedings of SIGGRAPH 2010) 29(4), Article 66, July 2010.
• Hill, S. Perpendicular Possibilities. http://blog.selfshadow.com/2011/10/17/perp-vectors/, October 2011.
• Frisvad, J. R. Building an orthonormal basis from a 3d unit vector without normalization. Journal of Graphics Tools 16(3), pp. 151-159, August 2012.
• Matsuda, K., and Lea, R. WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL. Addison-Wesley, 2013.
• Duff, T., Burgess, J., Christensen, P., Hery, C., Kensler, A., Liani, M., and Villemin, R. Building an orthonormal basis, revisited. Journal of Computer Graphics Techniques 6(1), pp. 1-8. March 2017.
• Max, N. Improved accuracy when building an orthonormal basis. Journal of Computer Graphics Techniques 6(1), pp. 9-16. March 2017.