diff options
Diffstat (limited to 'report/report.tex')
| -rw-r--r-- | report/report.tex | 119 |
1 files changed, 119 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} |
