\documentclass[12pt,a4paper]{article}

\usepackage{amstext}
%\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{stmaryrd}
\usepackage{enumerate}
\usepackage{alltt}
\usepackage[latin1]{inputenc}
\usepackage{cancel}
\usepackage{fancyhdr}
\usepackage{pstricks}
%\usepackage{pst-plot}
\usepackage{ngerman}

\title{\textsc{Computer Graphics I \\ \large Assignment 9 \\ \small Group III (Yavor Kaloyanov)}}
\author{\shortstack[c]{Jan Hendrik Dithmar\\ \footnotesize 2031259} \and \shortstack[c]{Pascal Gwosdek\\ \footnotesize 2505221}}
\date{}

\pagestyle{fancy}

\lhead{Assignment 9}
\chead{}
\rhead{Dithmar (2031259), Gwosdek (2505221)}
\lfoot{Computer Graphics 1}
\cfoot{Page \thepage}
\rfoot{WS 2006/2007}

\begin{document}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\newcommand{\exercise}[1]{\subsection{#1}}
\renewcommand{\theenumi}{\textbf{\alph{enumi}}}

\newcommand{\AND}{\ensuremath{\wedge}}
\newcommand{\OR}{\ensuremath{\vee}}
\newcommand{\SetR}{\ensuremath{\mathbb{R}}}
\newcommand{\SetN}{\ensuremath{\mathbb{N}}}
\newcommand{\SetC}{\ensuremath{\mathbb{C}}}
\newcommand{\SetZ}{\ensuremath{\mathbb{Z}}}
\newcommand{\SetQ}{\ensuremath{\mathbb{Q}}}
\newcommand{\SetB}{\ensuremath{\mathbb{B}}}
\newcommand{\QED}{\ensuremath{\hspace*{\fill}\square}}
\newcommand{\FLASH}{\ensuremath{\hspace*{\fill}\lightning}}
\newcommand{\OnotO}{\ensuremath{\mathcal{O}}}
\newcommand{\bild}[4]{
	\begin{figure}[htpb]
		\centering
			\includegraphics[width=#1cm]{#2}\\[0.2cm]
			\caption{#3}
			\label{#4}
	\end{figure}
	}

\newcommand{\m}[1]{\begin{pmatrix}#1\end{pmatrix}}
\newcommand{\+}{\phantom{-}}
\newcommand{\f}{\frac}

\maketitle

\thispagestyle{empty}

\newpage
\setcounter{page}{1}
\setcounter{section}{9}

\exercise{Homogenous Coordinates}
\begin{enumerate}
\item Let $\tilde{m} = (x,y,z,w)$ be an homogenous point. Then this point represents the point $m=\left(\dfrac{x}{w}, \dfrac{y}{w}, \dfrac{z}{w}\right)$ in euclidean
coordinates, except for $w=0$ (these points are located at infinity). \\
Now we multiply our point $\tilde{m}$ with an arbitrary $\alpha \neq 0$:
\begin{align*}
\tilde{m} ' = \alpha \tilde{m} & = \alpha \cdot (x,y,z,w) \\
& = (\alpha x, \alpha y, \alpha z, \alpha w)
\end{align*}
To get the euclidean point, that is represented by this homogenous point $\tilde{m}'$ we divide the first three components again by the forth:
$$m' = \left(\dfrac{\alpha x}{\alpha w}, \dfrac{\alpha y}{\alpha w}, \dfrac{\alpha z}{\alpha w}\right) = \left(\dfrac{x}{w}, \dfrac{y}{w}, \dfrac{z}{w}\right) = m$$ \QED

\item Figure: \\
\begin{pspicture}(0.5,0.5)(5.5,4.5)
\psline{->}(1,1)(2,2)
\psline(2,2)(5,2)
\psline(2,2)(3.5,4)
\psline(3.5,4)(5,2)

\psline[linestyle=dashed](2,2)(4.25,3)
\psline[linestyle=dashed](2.75,3)(5,2)
\psline[linestyle=dashed](3.5,2)(3.5,4)

\psdot(2,2)
\psdot(5,2)
\psdot(3.5,4)
\psdot(3.5,2.667)
\psdot(2.75,3)
\psdot(4.24,3)
\psdot(3.5,2)
\psdot(1,1)

\rput(0.75,0.75){0}
\rput(1.75,2.25){$p_0$}
\rput(5.25,1.75){$p_1$}
\rput(3.5,4.25){$p_2$}
\rput(3.5,1.70){$m_1$}
\rput(2.25,3){$m_3$}
\rput(4.75,3){$m_2$}
\rput(4,2.667){$m$}

\end{pspicture}

To get the center $m=(m_x, m_y, m_z)$ between three points $p_0 = (a_0, b_0, c_0)$, $p_1 = (a_1, b_1, c_1)$ and $p_2 = (a_2, b_2, c_2)$ in euclidean coordinates
we make the following computations:
$$m_1 = \dfrac{p_0 + p_1}{2}$$
By the properties of the barycenter in a triangle we get:
\begin{align*}
m & = m_1 + \dfrac{1}{3} \cdot (p_2 - m_1) \\
& = \dfrac{p_0 + p_1}{2} + \dfrac{2p_2 - p_0 - p_1}{3 \cdot 2} \\
& = \dfrac{3p_0 + 3p_1 + 2p_2 - p_0 - p_1}{6} \\
& = \dfrac{2p_0 + 2p_1 + 2p_2}{6} \\
& = \dfrac{p_0 + p_1 + p_2}{3}
\end{align*}
Now we'll make the component wise addition of the three points in homogenous coordinates:
$$\tilde{m} = \left(\begin{array}{c}a_0 \\ b_0 \\ c_0 \\ 1\end{array}\right) + \left(\begin{array}{c}a_1 \\ b_1 \\ c_1 \\ 1\end{array}\right) + \left(\begin{array}{c}a_2 \\ b_2 \\ c_2 \\ 1\end{array}\right) = \left(\begin{array}{c}a_0 + a_1 + a_2 \\ b_0 + b_1 + b_2 \\ c_0 + c_1 + c_2 \\ 3\end{array}\right)$$
In euclidean coordinates $\tilde{m}$ is:
$$\dfrac{1}{3} \cdot \left(\begin{array}{c}a_0 + a_1 + a_2 \\ b_0 + b_1 + b_2 \\ c_0 + c_1 + c_2\end{array}\right) = \dfrac{p_0 + p_1 + p_2}{3} = m$$ \QED

\item Define the addition $\oplus$ between two homogenous points $\tilde{a}, \tilde{b}$ as follows:
$$\tilde{a} \oplus \tilde{b} = \left(\begin{array}{c}a_x b_w + b_x a_w \\ a_y b_w + b_y a_w \\ a_z b_w + b_z a_w \\ b_w a_w\end{array}\right)$$
The corresponding euclidean point for $\tilde{a} \oplus \tilde{b}$ is then
$$\dfrac{1}{b_w a_w} \cdot \left(\begin{array}{c}a_x b_w + b_x a_w \\ a_y b_w + b_y a_w \\ a_z b_w + b_z a_w\end{array}\right)$$
The corresponding euclidean point to $\tilde{a}$ is $a = \left(\dfrac{a_x}{a_w}, \dfrac{a_y}{a_w}, \dfrac{a_z}{a_w}\right)^T$ (with $a_w \neq 0$).
For $\tilde{b}$ we obtain $b$ analogously. \\
Then we get for the standard addition:
$$a+b = \left(\begin{array}{c}\dfrac{a_x}{a_w} + \dfrac{b_x}{b_w} \\ \dfrac{a_y}{a_w} + \dfrac{b_y}{b_w} \\ \dfrac{a_z}{a_w} + \dfrac{b_z}{b_w}\end{array}\right) = \left(\begin{array}{c}\dfrac{a_x b_w + b_x a_w}{a_w b_w} \\ \dfrac{a_y b_w + b_y a_w}{a_w b_w} \\ \dfrac{a_z b_w + b_z a_w}{a_w b_w}\end{array}\right)$$
Now it is obvious that $(\tilde{a} \oplus \tilde{b})$ is the corresponding homogenous point to the euclidean one $(a+b)$.
\end{enumerate}

%\exercise{Perspective Projection}

%\exercise{Perspective Projection}

\setcounter{subsection}{3}
\exercise{Homogenous Lines in 2D*}
Claim:
$$\left(\begin{array}{c}p_x \\ p_y \\ p_w\end{array}\right) \times \left(\begin{array}{c}q_x \\ q_y \\ q_w\end{array}\right) = \left(\begin{array}{c}a \\ b \\ c\end{array}\right)$$
where $ax + by + c = 0$ is the line through $p$ and $q$. \\[0.3cm]
Proof:
\begin{align*}
a &= p_y q_w - p_w q_y \\
b &= p_w q_x - p_x q_w \\
c &= p_x q_y - p_y q_x
\end{align*}
Test if $p$ is on the line:
\begin{align*}
& (p_y q_w - p_w q_y) \dfrac{p_x}{p_w} + (p_w q_x - p_x q_w) \dfrac{p_y}{p_w} + (p_x q_y - p_y q_x) \\
= \quad & \dfrac{p_x p_y q_w}{p_w} - p_x q_y + p_y q_x - \dfrac{p_x p_y q_w}{p_w} + p_x q_y - p_y q_x \\
= \quad & 0
\end{align*}
Test if $q$ is on the line:
\begin{align*}
& (p_y q_w - p_w q_y) \dfrac{q_x}{q_w} + (p_w q_x - p_x q_w) \dfrac{q_y}{q_w} + (p_x q_y - p_y q_x) \\
= \quad & p_y p_x - \dfrac{p_w q_y q_x}{q_w} + \dfrac{p_w q_x q_y}{q_w} - p_x q_y + p_x q_y - p_y q_x \\
= \quad & 0
\end{align*}
\QED

\end{document}
