summaryrefslogtreecommitdiff
path: root/report
diff options
context:
space:
mode:
authorTom Harley2019-04-19 16:11:26 +0100
committerTom Harley2019-04-19 16:11:26 +0100
commit0be2f6f8ce0ec9c17453c59ef9f9d150ac7c3c08 (patch)
tree3b7a58041eb9d264b72c95c44a105a4cca9cd6d0 /report
downloadbezier-master.tar.gz
bezier-master.zip

Initial commit

HEADmaster
Diffstat (limited to 'report')
-rw-r--r--report/report.tex119
-rw-r--r--report/stacs_cw.cls106
2 files changed, 225 insertions, 0 deletions
diff --git a/report/report.tex b/report/report.tex
new file mode 100644
index 0000000..1744d89
--- /dev/null
+++ b/report/report.tex
@@ -0,0 +1,119 @@
+\documentclass{stacs_cw}
+
+\def\name{\emph}
+
+\matrno{150001937}
+
+\begin{document}
+
+\section{Introduction}
+
+B\'ezier curves and surfaces are a fundamental aspect of modern
+three-dimensional computer graphics. The ability to produce and manipulate these
+elements is crucial to forming smooth-looking surfaces in computer-generated
+imagery.
+
+For this practical, a B\'ezier curve visualiser was implemented in
+\name{Python}.
+
+As extensions, a convex hull visualiser was written in \name{Nim}, and the
+rendering of $n$-dimensional space was explored in \name{Idris}.
+
+\section{Building and Running the Submission}
+
+\subsection{Python B\'ezier Curve Visuliser}
+
+The Python code provided relies on one external library:
+
+\begin{verbatim}
+ pip3 install --user pysdl2
+\end{verbatim}
+
+After installation, the script \file{basic.py} can be run with \code{python3} on
+the lab machines.
+
+Left-clicking in the window will produce a control point. A B\'ezier curve will
+be drawn using control points chosen by the user. A tangent vector, as well as
+the vectors perpendicular to the tangent vector, will be rendered for the point
+where the parameter $t = 0.5$.
+
+\subsection{Nim Convex Hull Visualiser}
+
+A script is provided in the \file{nim} folder that will interactively install
+\code{nim} and \code{nimble} on the lab machines. After running this script, the
+command \code{nimble build} should compile the code into an executable that,
+when run, produces an SVG file with 100 randomly-placed points and their convex
+hull.
+
+\subsection{Idris $n$-dimensional B\'ezier Visualiser}
+
+The provided Idris code fails to run. The wrapper for \name{SDL} foreign
+functions causes a segmentation fault to occur when using mouse events, which is
+necessary for the implementation. The code has been included as evidence of
+effort.
+
+\section{Finding the Tangent Vector}\label{sec:tangent}
+
+The tangent vector was found by taking two sample points on the curve --- one on
+either side of the point for which the tangent vector was to be found. From
+these two points, $dx$ and $dy$ were calculated. These two values form an
+approximation of the tangent vector. The closer the sample points are to the
+original point, the more accurate this approximation will be.
+
+\section{Finding the Curvature Vector}
+
+One of the two vectors perpendicular to the tangent vector is the curvature
+vector. The submission does not discern this, and as such renders both of these
+vectors.
+
+One way to determine which of the two is the curvature vector would be to take a
+point along each of the vectors in question, and compare their distances to
+either of the sample points used in \S\ref{sec:tangent}. Except in corner cases,
+the curvature vector would be the vector with the shorter distance.
+
+Another option for finding the curvature vector is to find the second-order
+derivative of the curve, by using the $dx$/$dy$ pair mentioned earlier with
+other samples.
+
+\section{Extension: Convex Hull}
+
+The \name{Jarvis March} algorithm was implemented in Nim to find the convex hull
+of a set of points.
+
+The implementation seems to fail at times when approaching the top-right corner.
+This may be because rather than finding the ``left-most'' point (as described in
+the algorithm's
+pseudocode),
+the implementation finds the point with the smallest difference in angle.
+Floating-point arithmetic, or trigonometric inaccuracies in the functions being
+used, may cause the implementation to choose an incorrect point.
+
+\section{Extension: $n$-dimension B\'ezier... Things?}
+
+In 2D it's a B\'ezier curve, in 3D it's a B\'ezier surface, but what name does
+it gain after that point?
+
+Writing one set of functions for rendering in an arbitrary number of dimensions
+is tricky in a traditional language. In a dynamically-typed language, the number
+of dimensions elements exist in has to be constantly asserted to be equal to the
+other elements in use; in a statically-typed variant functions would have to be
+written for every $n$ dimensions. It was concluded that a statically-typed
+language with dynamic types would allow for the creation of functions that could
+handle any number of dimensions, while keeping all the assertions of degree to
+compile-time.
+
+Implementing this in Idris was significantly more difficult than had been
+originally predicted. Pile on top the fact that Idris is difficult to build on
+the lab machines, and that it lacks a package manager...
+
+I was very close to completing my goal. The final version for submission exists
+in \file{thing.idr}. This file is one function away from being able to calculate
+sample points for an arbitrary dimension count. I was so close! When I found out
+that the \name{SDL} bindings were temperamental, however, I abandoned it to
+complete the basic specification in Python.
+
+A lot of the work in \file{thing.idr} is work that noone else has ever attempted
+in Idris before --- it's quite cool to think I was working on something noone
+else has done before, even if I didn't quite finish it.
+
+\end{document}
diff --git a/report/stacs_cw.cls b/report/stacs_cw.cls
new file mode 100644
index 0000000..a5d7405
--- /dev/null
+++ b/report/stacs_cw.cls
@@ -0,0 +1,106 @@
+% Style file for producing University of St Andrew's Computer Science report - 2018
+% Work-in-Progress [Last Updated: 2018-11-05]
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesClass{stacs_cw}[St Andrews' Computer Science coursework template]
+
+%% Load article as base class
+\LoadClass[a4paper,11pt]{article}
+%% Layout
+\RequirePackage[a4paper,headheight=14pt,width=150mm,top=25mm,bottom=25mm]{geometry}
+\RequirePackage{graphicx}
+\RequirePackage{setspace}
+\RequirePackage{float}
+%Font
+\RequirePackage{libertine}
+\RequirePackage{libertinust1math}
+\RequirePackage{inconsolata}
+%% Language and Encoding
+\RequirePackage[UKenglish]{babel}
+\RequirePackage[utf8]{inputenc}
+\RequirePackage[T1]{fontenc}
+%% Formatting
+\RequirePackage{microtype}
+\RequirePackage{xcolor}
+\RequirePackage{hyperref}
+\RequirePackage{parskip}
+%% Feature inclusion
+\RequirePackage{listings}
+\RequirePackage{fancyhdr}
+% Title
+\RequirePackage{titletoc}
+\RequirePackage{titlesec}
+%% Maths
+\RequirePackage{amsmath}
+\RequirePackage{amssymb}
+% Bibliography
+\RequirePackage{natbib}
+%% Colours
+\definecolor{st-a-gray}{gray}{0.95}
+\definecolor{st-a-blue}{HTML}{00539b}
+\definecolor{st-a-red}{HTML}{ee312a}
+\definecolor{st-a-yellow}{HTML}{ffdf00}
+\definecolor{st-a-black}{HTML}{231f20}
+\definecolor{st-a-light-blue}{HTML}{00aeef}
+\definecolor{st-a-mid-blue}{HTML}{007dc5}
+\definecolor{st-a-burgundy}{HTML}{c60c46}
+\definecolor{st-a-purple}{HTML}{7b439a}
+\definecolor{st-a-orange}{HTML}{f5842b}
+\definecolor{st-a-green}{HTML}{54b948}
+\definecolor{st-a-mid-green}{HTML}{00853f}
+\definecolor{st-a-dark-green}{HTML}{005953}
+%% Hyperlink colouring
+\hypersetup{
+ colorlinks=true,
+ linkcolor=st-a-blue,
+ filecolor=st-a-burgundy,
+ urlcolor=cyan,
+}
+%% Code Listing style
+\lstset{
+ basicstyle=\small\ttfamily,
+ columns=flexible,
+ breaklines=true,
+ backgroundcolor=\color{st-a-gray},
+ numberstyle=\ttfamily,
+ frame=tb
+}
+%% Matriculation Number
+\def\matrno#1{\def\@matrno{#1}}
+\newcommand{\printmatrno}{\@matrno}
+%% Code command listing
+\def\code#1{\colorbox{st-a-gray}{\texttt{#1}}}
+%% File listing
+\def\file#1{\textcolor{st-a-burgundy}{\texttt{#1}}}
+%% Main matter header style
+\pagestyle{fancy}
+\rhead{\printmatrno}
+\renewcommand{\sectionmark}[1]{\markright{#1}} %% Suppress section numbering in lhead
+%% Define default document text colour
+\color{st-a-black}
+%% Title page
+\def\@maketitle{
+ \pagestyle{empty}
+ \null
+ \vspace{0.3\textheight}
+ \begin{center}
+ {\LARGE\bfseries \@title \par}
+ \vskip 1.5em
+ {\Large \@matrno}
+ \vskip 1.em
+ {\Large \@date}
+ \end{center}
+ \newpage
+ \clearpage
+ \pagenumbering{arabic}
+}
+% Table of Contents
+\renewcommand\tableofcontents{
+ \null\hfill\textbf{\Large\contentsname}\hfill\null\par
+ \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
+ \thispagestyle{empty}
+ \@starttoc{toc}%
+ \newpage
+ \clearpage
+ \pagenumbering{arabic}
+}