Skip to content

Commit 0c0353e

Browse files
committed
Add citations, perpendicular bisector part, figures
1 parent 08b24e7 commit 0c0353e

8 files changed

+1078
-6
lines changed

bitgeom.tex

+118-6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
\definecolor{blackoutline}{RGB}{14,14,14}
6868
\definecolor{bgcolor}{rgb}{0.95,0.95,0.95}
6969
\definecolor{red}{rgb}{1,0,0}
70+
\definecolor{venetianred}{RGB}{200,8,21}
7071
\definecolor{gray}{RGB}{24,24,24}
7172
\definecolor{thered} {rgb} {0.65,0.04,0.07}
7273
\definecolor{thegreen} {rgb} {0.06,0.44,0.08}
@@ -140,7 +141,6 @@
140141
\title{\titletext{}}
141142
\newcommand\subtitle{an introduction to basic \bitmap{} mathematics and algorithms with code samples in \Rust{}}
142143
\newcommand\coversubtitle{\TitleOutline{an introduction to basic \bitmap{} mathematics and algorithms with code samples in \Rust{}}}
143-
\newcommand\biblatex{\texttt{biblatex}\xspace}%
144144
\hypersetup{
145145
pdftitle={\titletext{}},
146146
pdfauthor={epilys},
@@ -203,6 +203,21 @@
203203
{\vfill{}\noindent{}\centering{}\symbola{}⸎\par}%
204204
}
205205

206+
\usepackage[
207+
indexing=false,
208+
bibstyle=numeric,
209+
citestyle=numeric,
210+
backref=true,
211+
datecirca=true,
212+
dateuncertain=true,
213+
dateabbrev=false,
214+
sorting=none,
215+
datezeros=false,% pad date components with zeros?
216+
dateera=secular,
217+
defernumbers=true,
218+
]{biblatex}
219+
\addbibresource{cite.bib}
220+
206221
\begin{document}
207222
\pagestyle{plain}
208223
\assignpagestyle{\chapter}{plain}
@@ -921,6 +936,42 @@ \section*{The code}
921936
%
922937
%
923938
%
939+
\section{Find perpendicular to line segment $AB$ that passes through its middle (perpendicular bisector of $AB$)}\label{sec:perp-bisector}
940+
941+
Find midpoint $m_{AB}$ of $AB$:
942+
943+
\begin{align*}
944+
m_{AB} = (\frac{x_a+x_b}{2}, \frac{y_a+y+b}{2})
945+
\end{align*}
946+
947+
Slope of $AB$ is $m_l = \frac{y_b-y_a}{x_b-x_a}$
948+
949+
Slope of perpendicular will be $m_p \times{} m_l \implies{} m_p = \frac{-1}{m_l}$
950+
951+
Perpendicular satisfies line equation $y = mx+c$ and passes through midpoint $m_{AB}$:
952+
$c = y_{AB} - m_p \times{} x_{AB}$.
953+
954+
\begin{minted}{rust}
955+
fn perp_bisector((x_a, y_a): Point, (x_b, y_b): Point) -> (i64, i64, i64) {
956+
let m_a = if x_b != y_b { (y_a - y_b) as f64 } else { -1.0 };
957+
let m_b = (x_b - x_a) as f64;
958+
959+
let (x_m, y_m) = ((x_b + x_a) as f64 / 2.0, (y_b + y_a) as f64 / 2.0);
960+
// slope form y=mx+b
961+
// m_og = (y_m - y_n / x_m - x_n)
962+
// m_og * m = -1 => m = (x_n - x_m) / (y_m - y_n) = m_b / m_a
963+
//
964+
// y = mx+b => y_m = m*x_m + b => b = y_m - m * x_m
965+
//
966+
// slope form y=mx+b -> implicit form αx+βy=γ
967+
// y = m*x + y_m - m* x_m
968+
(
969+
m_b as i64,
970+
-m_a as i64,
971+
(((y_m * m_a) - (m_b * x_m)) as i64),
972+
)
973+
}
974+
\end{minted}
924975
\chapter{Angle sectioning}
925976
\section{Bisection}\index{angle!bisectioning}
926977
\todo[inline]{Add \emph{angle bisectioning}}
@@ -942,7 +993,7 @@ \chapter{Drawing a line segment from its two endpoints}
942993
\input{figures/fig2.pdf_tex}
943994
\end{figure}
944995
945-
The algorithm presented here was first derived by Bresenham. In the \emph{Image} implementation, it is used in the \texttt{plot\_line\_width} method.
996+
The algorithm presented here was first derived by Bresenham.\cite{bresenham1996}In the \emph{Image} implementation, it is used in the \texttt{plot\_line\_width} method.
946997
% From graphic gems vol 1 p 99 (pdf page 124)
947998
\begin{minted}{rust}
948999
pub fn plot_line_width(&mut self, (x1, y1): (i64, i64), (x2, y2): (i64, i64)) {
@@ -1134,12 +1185,16 @@ \section{\emph{Fast} intersection of two line segments}
11341185
\clearpage{}
11351186
\myaddthumb{Shapes}{shapes}
11361187
\part{Shapes}
1137-
\skelpar%
1188+
\begin{figure}[H]
1189+
\centering
1190+
\includegraphics[width=\textwidth,keepaspectratio]{figures/shapes_concave_convex.pdf}
1191+
\par{\noindent{}In \emph{concave} shapes you cannot draw a \textcolor{venetianred}{line segment connecting any two of its points without going outside the shape}. In \emph{convex} shapes you can.}
1192+
\end{figure}
11381193
\chapter{Circles and Ellipses}
11391194
\begin{figure}[H]
11401195
\centering
1141-
\includegraphics[scale=0.5,keepaspectratio]{figures/circle_parts.pdf}
1142-
\includegraphics[scale=0.5,keepaspectratio]{figures/circle_parts2.pdf}
1196+
\includegraphics[scale=0.45,keepaspectratio]{figures/circle_parts.pdf}
1197+
\includegraphics[scale=0.45,keepaspectratio]{figures/circle_parts2.pdf}
11431198
{\par\scriptsize{}\textbf{Parts of a circle}. Figures reproduced from \emph{K. Morling - GEOMETRIC and ENGINEERING DRAWING, second edition, 1974}}
11441199
\end{figure}
11451200
\section{Equations of a circle and an ellipse}\label{sec:equations-circles}
@@ -1210,25 +1265,72 @@ \subsection{Construction with given center and radius/radiii.}
12101265
}
12111266
}
12121267
\end{minted}
1268+
%
1269+
%
12131270
\subsection{Circle from three given points}\index{circle!out of three points}
1214-
The naive way: Calculate the lines defined by the line segments created by taking a point and one of each of the rest. The order and pairings don't matter. The intersection point of their perpendiculars that pass through the middle of those line segments is the circle's center.
1271+
\begin{figure}[H]
1272+
\centering
1273+
\includegraphics[scale=0.5,keepaspectratio]{figures/circle3points.png}
1274+
\end{figure}
1275+
The naïve way: Calculate the lines defined by the line segments created by taking a point and one of each of the rest. The order and pairings don't matter. The intersection point of their perpendiculars that pass through the middle of those line segments is the circle's center.
1276+
1277+
\noindent{}Find perpendicular bisector of line segment: See \emph{\nameref{sec:perp-bisector}} page \pageref{sec:perp-bisector}
1278+
1279+
\noindent{}Find intersection point of lines: See \emph{\nameref{ch:intersection-lines}} page \pageref{ch:intersection-lines}
1280+
1281+
\attachsource{src/bin/circle3points.rs}\noindent{}The code:
1282+
\begin{minted}{rust}
1283+
let mut p_a = (35, 35);
1284+
let mut p_b = (128, 250);
1285+
let mut p_c = (179, 220);
1286+
let mut image = Image::new(WINDOW_WIDTH, WINDOW_WIDTH, 0, 0);
1287+
image.plot_circle(p_a, 3, 0.);
1288+
image.plot_circle(p_b, 3, 0.);
1289+
image.plot_circle(p_c, 3, 0.);
1290+
1291+
let perp1 = perp_bisector(p_a, p_b);
1292+
let perp2 = perp_bisector(p_b, p_c);
1293+
1294+
let centre = find_intersection(perp1, perp2);
1295+
let radius = distance_between_two_points(centre, p_a);
1296+
1297+
image.plot_line_width(p_a, p_b, 2.5);
1298+
image.plot_line_width(p_b, p_c, 2.5);
1299+
image.plot_line_width(p_c, p_a, 2.5);
1300+
image.plot_circle(centre, radius as i64, 2.0);
1301+
image.draw(&mut buffer, BLACK, None, WINDOW_WIDTH);
1302+
\end{minted}
1303+
%
1304+
%
12151305
\subsection{Circle inscribed in given polygon (e.g. a triangle) as list of vertices}
12161306
Bisect any two angles and take the intersection point of the bisecting lines. This point, called the
12171307
\emph{incentre} is the centre of the circle and the distance of the centre from the line defined by any side is the radius.
1308+
%
1309+
%
12181310
\subsection{Circumscribed circle of given regular polygon (e.g. a triangle) as list of vertices}
12191311
Just like with three points, take the perpendicular lines through the middle point of any of two sides. Their intersection point, called the \emph{circumcentre} is the center of the circumscribed circle. The radius is the distance of the centre from any vertice.
1312+
%
1313+
%
12201314
\subsection{Circle that passes through given point $Α$ and point $Β$ on line $L$}
12211315
\todo[inline]{Add \emph{Circle that passes through given point $Α$ and point $Β$ on line $L$}}
12221316
\skelpar%
1317+
%
1318+
%
12231319
\subsection{Tangent line of given circle}
12241320
\todo[inline]{Add \emph{Tangent line of given circle}}
12251321
\skelpar%
1322+
%
1323+
%
12261324
\subsection{Tangent line of given circle that passes through point $P$}
12271325
\todo[inline]{Add \emph{Tangent line of given circle that passes through point $P$}}
12281326
\skelpar%
1327+
%
1328+
%
12291329
\subsection{Tangent line common to two given circles}
12301330
\todo[inline]{Add \emph{Tangent line common to two given circles}}
12311331
\skelpar%
1332+
%
1333+
%
12321334
\clearpage{}
12331335
\section{Bounding circle}
12341336
\index{circle!bounding}%
@@ -1731,6 +1833,7 @@ \chapter{Triangle filling}\index{triangle!filling}\index{flood filling!triangle
17311833
17321834
\chapter{Flood filling}\index{flood filling}\index{bucket filling|see {flood filling}}\index{area filling|see {flood filling}}
17331835
\todo[inline]{Add \emph{Flood filling}}
1836+
\cite{Shani-1980}
17341837
\skelpar%
17351838
% Graphics gems vol 1. pdf page 296 "SEED FILL"
17361839
% Graphics gems vol 1. pdf page 299 "FILLING A REGION IN A FRAMEBUFFER"
@@ -1750,6 +1853,7 @@ \section{Centre of arc which blends two given circles}
17501853
\todo[inline]{Add \emph{Centre of arc which blends two given circles}}
17511854
\skelpar%
17521855
\section{Join segments with round corners}\label{sec:roundcorners}
1856+
\cite{gragevol3-225}
17531857
% Graphics gems vol 3. pdf page 225 "JOINING TWO LINES WITH A CIRCULAR ARC FILLET"
17541858
\begin{wrapfigure}{r}{0.5\textwidth}
17551859
\vspace{-60pt}
@@ -2941,6 +3045,14 @@ \chapter{Marching squares}\index{marching squares}\index{contour|see {marching s
29413045
\backmatter
29423046
\bookmarksetup{startatroot}
29433047
\cleardoublepage
3048+
\printbibheading[
3049+
heading=bibintoc, % bibintoc adds the Bibliography to the table of contents
3050+
]
3051+
\phantomsection % Requires hyperref package
3052+
\printbibliography[title={Bibliography}]
3053+
\cleardoublepage
3054+
\bookmarksetup{startatroot}
3055+
\cleardoublepage
29443056
\printindex
29453057
\cleardoublepage
29463058
\bookmarksetup{startatroot}

build/bitgeom.pdf

18 KB
Binary file not shown.

cite.bib

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@article{Shani-1980,
2+
doi = {10.1145/965105.807511},
3+
title = {Filling regions in binary raster images},
4+
author = {Shani, Uri},
5+
journal = {ACM SIGGRAPH Computer Graphics 1980-jul 01 vol. 14 iss. 3},
6+
year = {1980},
7+
month = {jul},
8+
day = {01},
9+
volume = {14},
10+
issue = {3},
11+
page = {321--327},
12+
url = {libgen.li/file.php?md5=639b871b82973f516b0218ba74b376f7},
13+
}
14+
@book{gragevol3-225,
15+
title = {Graphics gems},
16+
volume = {3},
17+
page = {225},
18+
chapter = {JOINING TWO LINES WITH A CIRCULAR ARC FILLET},
19+
}
20+
@article{bresenham1996,
21+
title = {Pixel-Processing Fundamentals},
22+
year = {1996},
23+
month = {January},
24+
page = {74},
25+
journal = {IEEE Computer Graphics and Applications},
26+
}

figures/circle3points.png

6.89 KB
Loading

figures/shapes_concave_convex.pdf

3.24 KB
Binary file not shown.

0 commit comments

Comments
 (0)