\documentclass[a4paper,twocolumn]{article} \title{Toribash Head Texture Vertical Pixel Stretch Factor} \author{Anthony Cox} \usepackage{amsmath,amsthm} \providecommand{\abs}[1]{\lvert#1\rvert} \usepackage[british]{babel} \usepackage[pdfusetitle]{hyperref} \begin{document} \twocolumn[ \begin{@twocolumnfalse} \maketitle \begin{abstract} When you map a planar texture onto a sphere, the pixels are stretched vertically with more distortion towards the poles of the spheres. This document describes a formula to calculate the vertical stretching of the pixels. This document was written as a memorandum for a friend and not as a definitive piece of mathematical work. Use of the content of this document is entirely at your own risk. \end{abstract} \end{@twocolumnfalse} ] \section{Introduction} \label{sec:introduction} The formulas and methods described in this document relate to head textures in the game Toribash. As such, they refer to planar textures of 128px x 128px mapped onto a sphere. These formulas can be used for other texture sizes, but changes will have to be made for the constant values in them. \subsection{Motivation} \label{subsec:motivation} Through the use of these algorithms it is possible to more accurately map head textures for use in Toribash. \section{Formulas} \label{sec:formulas} As the pixel stretch factor is the same along an entire row of pixels on the planar texture, it is possible to model with a circle rather than a sphere for the sake of simplicity. The x coordinate of a point on the circumference of a circle with the y coordinate corresponding with the row of pixels we are interested in on the planar texture first needs to be calculated. A simple application of pythagoras' theorem will yield the result since the radius of the circle is known. The $y$ value used in \autoref{eqn:pythagoras} is measured in texture coordinates (0 at the top) rather than from the origin of the circle. \begin{equation}\label{eqn:pythagoras} \begin{split} h^2 &= x^2 + y_1^2\\ x &= \sqrt{h^2 - y_1^2}\\ &= \sqrt{64^2 - (64 - y)^2} \end{split} \end{equation} The angle of the gradient at this point on the sphere can be used for the pixel stretch factor and consists of calculating the derivative of the circle. \begin{equation}\label{eqn:derivative} \begin{split} \frac{dy}{dx} &= \frac{a-x}{y-b}\\ &= \frac{-x}{y - 64} \end{split} \end{equation} The derivative from \autoref{eqn:derivative} is now made to correspond to the amount of vertical stretching applied to the pixels when mapping to the sphere simply by calculating the inverse. \begin{equation}\label{eqn:stretch} \delta = \frac{1}{\abs{\frac{dy}{dx}}} + 1 \end{equation} $\delta$ is the pixel stretch factor at the given y coordinate. This value ranges from $1$ at the equator to $\infty$ at the pole of the sphere. At $45^\circ$ the stretch factor will be 2 and corresponds to a doubling in the height of the pixels when viewed from a point collinear with the poles of the sphere rather than from a point which lies on the equatorial plane. The given formulas have a range of $0 \leq y < 64$. For $64 < y \leq 128$ apply the function $y = 128 - y_1$. When $y = 64$, $\delta \equiv 1$ \end{document}