100% found this document useful (10 votes)
170 views

Download ebooks file Python Playground, 2nd Edition Mahesh Venkitachalam all chapters

Mahesh

Uploaded by

abinizprenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (10 votes)
170 views

Download ebooks file Python Playground, 2nd Edition Mahesh Venkitachalam all chapters

Mahesh

Uploaded by

abinizprenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Get ebook downloads in full at ebookmeta.

com

Python Playground, 2nd Edition Mahesh


Venkitachalam

https://ebookmeta.com/product/python-playground-2nd-edition-
mahesh-venkitachalam/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Python Playground Geeky Projects for the Curious


Programmer 2nd Edition Mahesh Venkitachalam

https://ebookmeta.com/product/python-playground-geeky-projects-for-
the-curious-programmer-2nd-edition-mahesh-venkitachalam/

ebookmeta.com

Quantum Mechanics Mahesh C Jain

https://ebookmeta.com/product/quantum-mechanics-mahesh-c-jain/

ebookmeta.com

Cambridge IGCSE and O Level History Workbook 2C - Depth


Study: the United States, 1919-41 2nd Edition Benjamin
Harrison
https://ebookmeta.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-
benjamin-harrison/
ebookmeta.com

Neither Good Nor Bad Why Human Beings Behave How They Do
1st Edition Gerhard Besier

https://ebookmeta.com/product/neither-good-nor-bad-why-human-beings-
behave-how-they-do-1st-edition-gerhard-besier/

ebookmeta.com
Childhood Today 1st Edition Alex Owen

https://ebookmeta.com/product/childhood-today-1st-edition-alex-owen/

ebookmeta.com

Lonely Planet Pacific Northwest s Best Trips 5 Road Trips


Guide 5th Edition Becky Ohlsen

https://ebookmeta.com/product/lonely-planet-pacific-northwest-s-best-
trips-5-road-trips-guide-5th-edition-becky-ohlsen/

ebookmeta.com

Bureaucratic Politics and Administration in Chile Peter S.


Cleaves

https://ebookmeta.com/product/bureaucratic-politics-and-
administration-in-chile-peter-s-cleaves/

ebookmeta.com

Optimization on Solution Sets of Common Fixed Point


Problems 1st Edition Alexander J. Zaslavski

https://ebookmeta.com/product/optimization-on-solution-sets-of-common-
fixed-point-problems-1st-edition-alexander-j-zaslavski/

ebookmeta.com

Savannah Mafia 1 Cruel Prince 1st Edition M A Lee

https://ebookmeta.com/product/savannah-mafia-1-cruel-prince-1st-
edition-m-a-lee/

ebookmeta.com
Problems in Physical Chemistry by Narendra Awasthi for JEE
15th Edition Narendra Avasthi

https://ebookmeta.com/product/problems-in-physical-chemistry-by-
narendra-awasthi-for-jee-15th-edition-narendra-avasthi/

ebookmeta.com
PY THON
PUT THE FUN
BACK IN
PROGRAMMING

P L AYG R OU N D

P Y T H O N P L AY G R O U N D
Python is a powerful programming language that’s • Make realistic animations with OpenGL shaders G E E K Y P R O J E C T S F O R T H E
easy to learn and fun to play with. But once you’ve by exploring particle systems, transparency, and
C U R I O U S P R O G R A M M E R
gotten a handle on the basics, what do you do next? billboarding techniques

Python Playground is a collection of imaginative • Construct 3D visualizations using data from CT and
programming projects that will inspire you to use MRI scans
Python to make art and music, build simulations of
MAHESH VENKITACHAL AM
• Build a laser show that responds to music by hooking
real-world phenomena, and interact with hardware
up your computer to an Arduino
like the Arduino and Raspberry Pi. You’ll learn to
use common Python tools and libraries like numpy, Programming shouldn’t be a chore. Have some solid,
matplotlib, and pygame to do things like: geeky fun with Python Playground.

• Generate Spirograph-like patterns using parametric ABOUT THE AUTHOR


equations and the turtle module
Mahesh Venkitachalam is a software engineer with
• Create music on your computer by simulating two decades of programming experience. He has
frequency overtones nurtured a passion for technology since the eighth
grade, which he channels into his popular electronics
• Translate graphical images into ASCII art
and programming blog, electronut.in.
• Write an autostereogram program that produces
3D images hidden beneath random patterns
The projects in this book are
compatible with Python 2 and 3.

VENKITACHALAM

T H E F I N E ST I N G E E K E N T E RTA I N M E N T ™
w w w.nostarch.com

$29.95 ($34.95 CDN)


“ I L I E F L AT .”
PYTHON
PROGRAMMING LANGUAGES/
SHELVE IN:

This book uses a durable binding that won’t snap shut.


Python Playground
Python
Playground
Geeky Projects for
the Curious Programmer

b y Ma h e s h Ve n ki t a c h a la m

San Francisco
Python Playground. Copyright © 2016 by Mahesh Venkitachalam.

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.

First printing

19 18 17 16 15   1 2 3 4 5 6 7 8 9

ISBN-10: 1-59327-604-4
ISBN-13: 978-1-59327-604-1

Publisher: William Pollock


Production Editor: Serena Yang
Cover Illustration: Josh Ellingson
Interior Design: Octopod Studios
Developmental Editor: William Pollock
Technical Reviewers: Nicholas Kramer and Raviprakash Jayaraman
Copyeditor: Kim Wimpsett
Compositor: Kathleen Miller
Proofreader: Paula L. Fleming

Figure 8-4 was created by Fred Hsu (March 2005) and has been reproduced under the Creative Commons
Attribution-Share Alike 3.0 Unported license.

For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:

No Starch Press, Inc.


245 8th Street, San Francisco, CA 94103
phone: 415.863.9900; [email protected]
www.nostarch.com

Library of Congress Cataloging-in-Publication Data

Venkitachalam, Mahesh.
Python playground : geeky projects for the curious programmer / by Mahesh Venkitachalam.
pages cm
Includes index.
ISBN 978-1-59327-604-1 -- ISBN 1-59327-604-4
1. Python (Computer program language) 2. Electronic apparatus and appliances--Automatic control.
3. Arduino (Programmable controller)--Programming. 4. Raspberry Pi (Computer)--Programming. I.
Title.
QA76.73.P98.V46 2015
005.13'3--dc23
2014046103

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other
product and company names mentioned herein may be the trademarks of their respective owners. Rather
than use a trademark symbol with every occurrence of a trademarked name, we are using the names only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.

The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
For my parents,
A.V. Venkitachalam and N. Saraswathy,
for giving me the greatest gift of all—
an education

&

For Hema
H = M 2A
Brief Contents

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

Part I: Warming Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: Parsing iTunes Playlists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Chapter 2: Spirographs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Part II: Simulating Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


Chapter 3: Conway’s Game of Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Chapter 4: Generating Musical Overtones with the Karplus-Strong Algorithm . . . . . . . . . . . . 55

Chapter 5: Boids: Simulating a Flock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Part III: Fun with Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87


Chapter 6: ASCII Art . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

Chapter 7: Photomosaics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Chapter 8: Autostereograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

Part IV: Enter 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131


Chapter 9: Understanding OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Chapter 10: Particle Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

Chapter 11: Volume Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

Part V: Hardware Hacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233


Chapter 12: Introduction to the Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

Chapter 13: Laser Audio Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

Chapter 14: A Raspberry Pi–Based Weather Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . 273

Appendix A: Software Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

Appendix B: Basic Practical Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

Appendix C: Raspberry Pi Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Conte nt s in De ta il

Acknowledgments xvii

Introduction xix
Who Is This Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Part I: Warming Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Part II: Simulating Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Part III: Fun with Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Part IV: Enter 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Part V: Hardware Hacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Why Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
Python Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
The Code in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

part I: Warming Up 1

1
Parsing iTunes Playlists 3
Anatomy of the iTunes Playlist File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Finding Duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Extracting Duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Finding Tracks Common Across Multiple Playlists . . . . . . . . . . . . . . . . . . . . . . . 7
Collecting Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Plotting Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2
Spirographs 17
Parametric Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Spirograph Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Turtle Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
The Spiro Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
The Setup Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The restart() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The draw() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Creating the Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
The SpiroAnimator Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The genRandomParams() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Restarting the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The update() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Showing or Hiding the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Saving the Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Parsing Command Line Arguments and Initialization . . . . . . . . . . . . . . . . . . . . 30
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Running the Spirograph Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

part II: Simulating Life 39

3
Conway’s Game of Life 41
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Representing the Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Implementing the Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Sending Command Line Arguments to the Program . . . . . . . . . . . . . . . . . . . . 47
Initializing the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Running the Game of Life Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4
Generating Musical Overtones with the
Karplus-Strong Algorithm 55
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Creating WAV Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
The Minor Pentatonic Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Implementing the Ring Buffer with deque . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Implementing the Karplus-Strong Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Writing a WAV File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Playing WAV Files with pygame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The main() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

x   Contents in Detail
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Running the Plucked String Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

5
Boids: Simulating a Flock 71
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Computing the Position and Velocities of the Boids . . . . . . . . . . . . . . . . . . . . . 73
Setting Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Drawing a Boid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Applying the Rules of the Boids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Adding a Boid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Scattering the Boids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Command Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The Boids Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Running the Boids Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

part iii: Fun with Images 87

6
ASCII Art 89
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Defining the Grayscale Levels and Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Computing the Average Brightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Generating the ASCII Content from the Image . . . . . . . . . . . . . . . . . . . . . . . . 93
Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Writing the ASCII Art Strings to a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . 95
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Running the ASCII Art Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

7
Photomosaics 101
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Splitting the Target Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Averaging Color Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Matching Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Contents in Detail   xi
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Reading in the Tile Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Calculating the Average Color Value of the Input Images . . . . . . . . . . . . . . . 105
Splitting the Target Image into a Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Finding the Best Match for a Tile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Creating an Image Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Creating the Photomosaic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Adding the Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Controlling the Size of the Photomosaic . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Running the Photomosaic Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

8
Autostereograms 117
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Perceiving Depth in an Autostereogram . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Depth Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Repeating a Given Tile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Creating a Tile from Random Circles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Creating Autostereograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Command Line Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Running the Autostereogram Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

part iv: Enter 3D 131

9
Understanding OpenGL 133
Old-School OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Modern OpenGL: The 3D Graphics Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Geometric Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
3D Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Vertex Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Texture Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Displaying OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

xii   Contents in Detail
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Creating an OpenGL Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Setting Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
The Scene Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
The Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Running the OpenGL Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

10
Particle Systems 159
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Modeling the Motion of a Particle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Setting a Maximum Spread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Rendering the Particles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Using OpenGL Blending to Create More Realistic Sparks . . . . . . . . . . . . . . . 164
Using Billboarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Animating the Sparks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
The Code for the Particle System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Defining the Particle Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Defining the Time-Lag Array for the Particles . . . . . . . . . . . . . . . . . . . . . . . . 168
Setting the Initial Particle Velocities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Creating the Vertex Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Creating the Fragment Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
The Camera Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
The Complete Particle System Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
The Box Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The Code for the Main Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Updating the Particles at Each Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
The Keyboard Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Managing the Main Program Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
The Complete Main Program Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

11
Volume Rendering 191
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Generating Rays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Displaying the OpenGL Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
An Overview of the Project Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Generating a 3D Texture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

Contents in Detail   xiii
The Complete 3D Texture Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Generating Rays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Defining the Color Cube Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Creating the Frame Buffer Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Rendering the Back-Faces of the Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Rendering the Front-Faces of the Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Rendering the Whole Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
The Resize Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
The Complete Ray Generation Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Volume Ray Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
The Vertex Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
The Fragment Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
The Complete Volume Ray Casting Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
2D Slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
The Vertex Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
The Fragment Shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
A User Interface for 2D Slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
The Complete 2D Slicing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Putting the Code Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
The Complete Main File Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

part v: Hardware Hacking 233

12
Introduction to the Arduino 235
The Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
The Arduino Ecosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Building the Light-Sensing Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
How the Circuit Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
The Arduino Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Creating the Real-Time Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
The Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
The Complete Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Experiments! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

xiv   Contents in Detail
Discovering Diverse Content Through
Random Scribd Documents
be the 1st, and 2nd terms of the question; the 3rd number is always of
the same name, or kind as the 4th, or answer sought; and in stating the
question it is always to be made the 3rd term. If the answer will be
greater than the 3rd term, place the least of the other two given
quantities for the 1st term; but if the answer will be less than the 3rd
term, put the greater of the two numbers, or quantities, for the 1st term.
Rule.—State the question according to the above directions, and
multiply the 2nd and 3rd terms together, and divide this product by the
1st, for the 4th term, or answer sought.
If the 1st and 2nd terms are not of the same denomination, they must
be reduced to it; and if the third term is a compound number, it must be
reduced to its lowest denomination before the multiplication, or division of
the term takes place.
Note 1.—The operation may frequently be considerably abridged, by
dividing the 1st and 2nd, or the 1st and 3rd terms, by any number which
will exactly divide them, afterwards using the quotients, instead of the
numbers themselves.*
Example.—If 2 tons of iron for ordnance cost £40, how many tons may
be bought for £360?
As £40 : £360 :: 2 tons : 18 tons.
(Thus 360 × 2) ÷ 40 = 18. The answer.
* Or thus, 9 × 2 = 18. The answer.
Note 2.—A concise method of ascertaining the annual amount of a daily
sum of money.
Rule.—Bring the daily sum into pence, and then add together as many
pounds, half pounds, groats, and pence, as there are pence in the daily
sum, for the amount required. For leap year, add the rate for one day.
Example.—Required the annual amount of 2s. 6d. per diem.
2s. 6d. = 30d. 30 pounds.
15 = 30 half pounds.
10s. = 30 groats.
2s. 6d. = 30 pence.
Annual amount (365 days) ... £45 12s. 6d.
Note 3.—To find the amount of any number of days’ pay, the daily rate
(under twenty shillings) being given.
The price of any article being given, the value of any number may be
ascertained in a similar manner.
Rule 1. When the rate (or price) is an even number, multiply the given
number by half of the rate, doubling the first figure to the right hand for
the shillings, the remainder of the product will be pounds.
Example. Required the amount of 243 days’ pay, at 4s. per diem.
4/2 = 2 243
2
£48 12s. Ans.

Rule 2. When the price is an odd number, find for the greatest number
as before, to which add one-twentieth of the given number for the odd
shilling.
Example. What is the price of 566 pairs of shoes, at 7s. per pair.
566 2/0 ) 56/6
3 28 6
169 16s.
28 6
£198 2s. Ans.

FRACTIONS.

A fraction is a quantity which expresses a part, or parts of a unit, or


integer. It is denoted by two numbers placed with a line between them.
A Simple fraction consists of two numbers, called the numerator, and
denominator; thus,
3 numerator,
5 denominator.

The Denominator is placed below the numerator, and expresses the


number of equal parts into which the integer is divided.
The Numerator expresses the number of parts of the broken unit, or
integer; or shows how many of the parts of the unit are expressed by the
fraction.
A Compound fraction is a fraction of a fraction, as ⅔ of ⅘.
A Mixed number consists of a whole number with a fraction annexed to
it, as 4⅖.
An Improper fraction has the numerator greater than the denominator,
as 6/5.

REDUCTION OF FRACTIONS.

is bringing them from one denomination to another.

To reduce a fraction to its lowest terms.


Rule.—Divide the numerator, and the denominator, by any number that
exactly divides them, and the quotients by any other number, till they can
be no longer divided by any whole number, when the fraction will be in its
lowest terms.

Example.—Reduce 4032 to its lowest terms.


6048
4 12 6 7
Thus, 4032 = 1008 = 84 = 14 = 2 Answer.
6048 1512 126 21 3.

To reduce an improper fraction to a whole, or mixed number.


Rule.—Divide the numerator by the denominator, the quotient will be
the whole number; and the remainder (if any) the numerator of the
fraction, having the divisor for the denominator.

Example.—Reduce 114 to a whole, or mixed number.


12

12 ) 114
6
9 12 Answer.

To reduce a mixed number to an improper fraction.


Rule.—Multiply the whole number by the denominator, and add the
numerator to the product, under which place the given denominator.
Example.—Reduce 17⅝ to an improper fraction.
17⅝
8
141
8 Answer.

To reduce a compound fraction to a simple fraction.


Rule.—Multiply all the numerators together for the numerator, and all
the denominators for the denominator.
Example.—Reduce ⅜ of ⅙ of ½ of 9 to a simple fraction.
Numerators 3 × 1 × 1 × 9 = 27 = 9
Answer.
Denominators 8 × 6 × 2 × 1 96 32

To reduce fractions of different denominators to equivalent fractions,


having a common denominator.
Rule.—Multiply each numerator by all the denominators except its own
for the new numerators, and multiply all the denominators together for a
common denominator.[42]
Example.—Reduce ⅜, ⅔, and ⅘ to fractions having a common
denominator.
3 × 3 × 5 = 45
2 × 8 × 4 = 80
4 × 8 × 3 = 96
45
8 × 3 × 5 = 120 Answer, , 80 , 96 .
120 120 120

ADDITION OF FRACTIONS.

Rule.—Bring compound fractions to simple fractions; reduce all the


fractions to a common denominator, then add all the numerators together,
and place their sum over the common denominator. When mixed numbers
are given, find the sum of the fractions, to which add the whole numbers.
Example.—Add together ⅚, ¾, and 6½.
40 36 24 4
5 × 4 × 2 = 40 48
+ 48
+ 48
+6=8 48
.
3 × 6 × 2 = 36
1 × 6 × 4 = 24 or, by cancelling, and dividing,[43]
10 9 6 1
6 × 4 × 2 = 48 12
+ 12 + 12 + 6 = 8 12 Answer.

SUBTRACTION OF FRACTIONS.

Rule.—Prepare the quantities, as in addition of fractions. Place the less


quantity under the greater. Then, if possible, subtract the lower numerator
from the upper; under the remainder write the common denominator, and,
if there be whole numbers, find their difference as in simple subtraction.
But if the lower numerator exceed the upper, subtract it from the common
denominator, and to the remainder add the upper numerator; write the
common denominator under this sum, and carry 1 to the whole number in
the lower line.
Example.—
From 54 5 or 54 25
6 30
5 10
Take 25 or 25
15 30
——
29 15 Answer.
30

MULTIPLICATION OF FRACTIONS.

Rule.—Reduce mixed numbers to equivalent fractions; then multiply all


the numerators together for a numerator, and all the denominators
together for a denominator, which will give the product required.
Example.—Multiply ⅚, ⅜, and 2½ together.
5 75
⅚ × ⅜ × (2½ or) 2
= 96
Answer.

DIVISION OF FRACTIONS.

Rule.—Prepare the fractions, as for multiplication; then divide the


numerator by the numerator, and the denominator by the denominator, if
they will exactly divide; but if they will not do so, then invert the terms of
the divisor, and multiply the dividend by it, as in multiplication.
Example.—Divide 9 by 4½.
16
9 9
16
÷ (4½ or) 2
=⅛ Answer.

RULE OF THREE IN FRACTIONS.

Rule.—State the terms, as directed in “Simple proportion;” reduce them


(if necessary) to improper, or simple fractions, and the two first to the
same denomination. Then multiply together the second and third terms,
and the first with its parts inverted, as in division, for the answer.
Example.—If 4⅕ cwt. of sugar cost £19⅞, how much may be bought
for £59⅝?
As 19⅞ : 59⅝ :: 4⅕
Or, 159
8
: 477
8
:: 21
5
: 12⅗ Answer.
8 477 21 80136
159
× 8
× 5
= 6360
= 12⅗ cwt.

DECIMALS.

A decimal fraction is that which has for its denominator an unit (1), with
as many ciphers annexed as the numerator has places; and it is usually
expressed by setting down the numerator only, with a point before it, on
the left hand. Thus, 5 is ·5; 25 is ·25; 25 is ·025; ciphers being
10 100 1000
prefixed, to make up as many places as are required by the ciphers in the
denominator.
A mixed number is made up of a whole number with some decimal
fraction, the one being separated from the other by a point, thus 3·25 is
the same as 3 25 or 325.
100 100

Ciphers on the right hand of decimals make no alteration in their value;


for ·5, ·50, ·500 are decimals having all the same value, each being = 5 .
10
But when they are placed on the left hand, they decrease the value in a
tenfold proportion; thus, ·5 is 5 ; but ·05 is 5 .
10 100

ADDITION OF DECIMALS.
Rule.—Set the numbers under each other, according to the value of
their places, in which state the decimal separating points will all stand
exactly under each other. Then beginning at the right hand, add up all the
columns of numbers as in integers, and point off as many places for
decimals as are in the greatest number of decimal places in any of the
lines that are added; or place the point directly below all the other points.
Example.—Required the sum of 29·0146, 3146·5, 14·16, and 165.
29·0146
3146·5
14·16
165·
Answer 3354·6746

SUBTRACTION OF DECIMALS.

Rule.—Place the numbers under each other according to the value of


their places. Then, beginning at the right hand, subtract as in whole
numbers, and point off the decimals, as in addition.
Example.—Subtract 4·90142 from 214·81.
214·81
4·90142
Answer 209·90858

MULTIPLICATION OF DECIMALS.

Rule.—Place the factors, and multiply them together, the same as if they
were whole numbers. Then point off in the product just as many places of
decimals as there are decimals in both the factors. But, if there be not so
many figures in the product, prefix ciphers to supply the deficiency.[44]
Example.—Multiply 32·108 by 2·5.
32·108
2·5
160540
64216
80·2700 Answer.

DIVISION OF DECIMALS.

Rule.—Divide as in whole numbers, and point off in the quotient as


many places for decimals as the decimal places in the dividend exceed
those in the divisor. When the decimal places of the quotient are not so
many as the above rule requires, the deficiency is to be supplied by
prefixing ciphers. When there is a remainder after the division, or when
the decimal places in the divisor are more than those in the dividend, then
ciphers may be annexed to the dividend, and the quotient carried on as
far as required.
Example.—Divide 234·7052 by 64·25.
64·25 ) 234·7052 ( 3·65 Answer.
19275
41955
38550
34052
32125
1927 Remainder.

REDUCTION OF DECIMALS.

To reduce a vulgar fraction to its equivalent decimal.


Rule.—Divide the numerator by the denominator, as in Division of
Decimals, annexing ciphers to the numerator as far as necessary: and the
quotient will be the decimal required.

Example.—Reduce 7 to a decimal.
24

24 = 4 × 6. Then 4 ) 7·

6 ) 1·75

·291666, &c.
To find the value of a decimal, in terms of the inferior denominations.
Rule.—Multiply the decimal by the number of parts in the next lower
denomination, and cut off as many places to the right hand for a
remainder, as there are places in the given decimal. Multiply that
remainder by the parts in the next lower denomination, again cutting off
for another remainder as before. Proceed in the same manner through all
the parts of the integer; then the several denominations, separated on the
left hand, will make up the answer.
Example.—What is the value of ·775 pounds sterling.
·775
20
Shillings 15·500
12
Pence 6·000 Answer 15s. 6d.

To convert integers, or decimals to equivalent decimals of higher


denominations.
Rule.—Divide by the number of parts in the next higher denomination,
continuing the operation to as many higher denominations as may be
necessary.
When there are several numbers, all to be converted to the decimal of
the highest—
Set the given numbers directly under each other for dividends,
proceeding from the lowest to the highest; opposite to each dividend, on
the left hand, place such a number for a divisor as will bring it to the next
higher name. Begin at the uppermost, and perform all the divisions,
placing the quotient of each division, as decimal parts, on the right hand
of the dividend next below it; so shall the last quotient be the decimal
required.
Example.—Convert 15s. 9¾d. to the decimal of a pound sterling.
4 3·
12 9·75
20 15·8125
£·790625 Answer.
Example.—Convert 1 dwt. to the decimal of a pound, Troy weight.
20 ) 1
12 ) ·05 oz.
·004166 lb., &c., Answer.

RULE OF THREE IN DECIMALS.

Rule.—Prepare the terms, by reducing the fractions to decimals;


compound numbers to decimals of the higher denominations, or integers
of the lower; also the first, and second terms to the same name. Then
multiply, and divide, as in the Rule of Three, in whole numbers.

Example.—If ⅜ of a yard of cloth cost £⅖, what will 5 of a yard cost?


16

yd. yd. £. s. d.
⅜ = ·375 As ·375 : ·3125 :: 4 : ·333 &c. or 6 8
4
⅖ = ·4 ·375) ·12500 (·3333 &c.
1125 20
5/16 = ·3215 1250s. 6·666 &c.
1125 12
Answer, 6s. 8d. 125d. 7·999 &c. nearly 8d.

DUODECIMALS.

By Duodecimals, artificers, &c., compute the content of their works.


Rule.—Set down the two dimensions to be multiplied together one
under the other, so that feet may stand under feet, inches under inches,
&c.
Multiply each term in the multiplicand, beginning at the lowest, by the
feet in the multiplier, and set the result of each straight under its
corresponding term, observing to carry 1 for every 12, from the inches to
the feet. In like manner multiply all the multiplicand by the inches, and
parts of the multiplier, and set the result of each term one place removed
to the right hand of those in the multiplicand: omitting, however, what is
below parts of inches, only carrying to these the proper number of units
from the lowest denominations. Or, instead of multiplying by the inches,
take such part of the multiplicand as those are of a foot.
Then add the two lines together for the content required.
Example.—Multiply 14 feet 9 inches, by 4 feet 6 inches.
ft. in.
14 9
4 6
59 0
7 4½
66 4½ Answer.

TABLES OF WEIGHTS, AND MEASURES.

TROY WEIGHT.

24 grains 1 pennyweight.
480 20 1 ounce.
5760 240 12 1 pound.
AVOIRDUPOIS WEIGHT.

16 drams 1 ounce.
256 16 1 pound.
7168 448 28 1 quarter.
hundred
28672 1792 112 4 1 weigh
t.
573440 35840 2240 80 20 1 ton.
Note.— 1 lb. Avoirdupois weight equals 14 oz. 11 dwts. 15½ grs. Troy.
1 oz. ditto 18 dwts. 5½ do.
1 dr. ditto 27·34375 do.

APOTHECARIES’ WEIGHT.

20 grains 1 scruple.
60 3 1 dram.
480 24 8 1 ounce.
5760 288 96 12 1 pound.

WEIGHTS.

To find the weight, for tonnage.


Cattle—
Divide the number by 3, for weight in tons.
Sheep Average 60 lb. each.
Divide by 33, for weight in tons.
Pigs Average 80 lb.
Divide by 15, for tons.
Beer, or Ale—
Barrel 3¼ cwt.
Hogshead 5¼ cwt.
Oats Sack—24 stone.
Divide quarters by 5, for tons.
Rum—
Divide gallons by 224, for tons.
Wine Cask—12 cwt.

Rule for ascertaining the weight of Hay.


Measure the length and breadth of the stack; then take its height from
the ground to the eaves, and add to this last one-third of the height from
the eaves to the top: Multiply the length by the breadth, and the product
by the height, all expressed in feet; divide the amount by 27, to find the
cubic yards, which multiply by the number of stones supposed to be in a
cubic yard (viz., in a stack of new hay, six stones; if the stack has stood a
considerable time, eight stones; and if old hay, nine stones), and you have
the weight in stones. For example, suppose a stack to be 60 feet in
length, 30 in breadth, 12 in height from the ground to the eaves, and 9
(the third of which is three) from the eaves to the top; then 60 × 30 × 15
= 27000; 27000 ÷ 27 = 1000; and 1000 × 9 = 9000 stones of old hay.
LONG MEASURE.

12 inches 1 foot.
36 3 1 yard.
198 16½ 5½ 1 pole, perch, or rod.
7920 660 220 40 1 furlong.
63360 5280 1760 320 8 1 mile.

LAND MEASURE (Length).

7·92 inches 1 link.


100 links, or 22 yards 1 chain.
80 chains 1 mile.
69·121 miles 1 geographical degree.
LAND MEASURE (Surface, or Superficial).

62·7264 square inches 1 square link.


625 square links 1 square pole, or perch.
10000 square links 1 square chain.
2500 square links 1 square rood, or pole.
10 square chains 1 square acre.
100000 square links 1 square acre.
NAUTICAL MEASURE.

1 nautical mile 6082·66 feet.


3 miles 1 league.
20 leagues 1 degree.
360 degrees the earth’s circumference.

SQUARE MEASURE.
144 s. inches 1 s. foot
1296 9 1 s. yard.
39204 272¼ 30¼ 1 s. pole.
1568160 10890 1210 40 1 rood.
6272640 43560 4840 160 4 1 acre.
CUBIC MEASURE (Measure of solidity).

1728 cubic inches 1 cubic foot.


27 cubic feet 1 cubic yard.
Note.—A cubic foot is equal to 2200 cylindrical inches,
or 3300 spherical inches, or 6600 conical inches.

Timber.
40 feet of round, and 50 feet of hewn timber make 1 Ton; 16 cubic feet
make 1 Foot of wood; 8 feet of wood make 1 Cord.

Water.
Maximum density 42 deg. Fahrenheit.
1 cubic foot of water 6¼ imperial gallons.
1 cylindric foot do. about 5 do.
1 cubic foot weighs 62·5 lb. avoirdupois.
1 cylindric do. do. 49·1
1 lineal do. (1 in. square) do. ·434
12·2 imperial gallons weigh 1 cwt.
224 do. do. 1 ton.
1·8 cubic feet do. 1 cwt.
35·84 do. do. 1 ton.

MEASURES OF CAPACITY.
69⅓ cubic in 2 pints 1 quart.
277¼ 8 4 1 gallon.
554½ 16 8 2 1 peck.
2218⅕ 64 32 8 4 1 bushel.
10¼ cubic ft. 512 256 64 32 8 1 quarter.

FRENCH MEASURES.
English English
cubic inches. feet.
Metre 3·281
Millilitre ·06103 ” French feet, 3·07844
Centilitre ·61028 Millimetre. ·03937
Decilitre 6·10279 Centimetre ·39371
Litre, or cubic decimetre 61·02791 Decimetre 3·93708
Decalitre 610·27900 Metre 39·37079
Hectolitre 6102·79000 Decametre 393·70790
Kylolitre 61027·90000 Hectometre 3937·07900
Myrialitre 610279·00000 Kilometre 39370·79000
1 litre is nearly 2⅛ wine pints. Myriametre 393707·90000
1 kilolitre 1 tun 12¾ wine gallons. 8 kilometres are nearly 5 miles.
1 stere, or cubic metre 35·3171 1 inch is ·0254 metre.
100 feet are nearly 30·5 metres.

INVOLUTION.

Involution is the raising of powers from any given number, as a root.


A Power is a quantity produced by multiplying any given number, called
the Root, a certain number of times continually by itself. Thus, 2 × 2 = 4,
the 2nd power, or square of 2, expressed thus, 22.
The index, or exponent of a power is the number denoting the height,
or degree of that power. Thus, 2 is the index of the 2nd power.
Powers that are to be raised, are usually denoted by placing the index
above the root, or first power.
Thus 22 = 4, the 2nd power of 2.
Example.—What is the 2nd power of 45?
45 × 45 = 2025 Answer.

EVOLUTION.

Evolution is the reverse of Involution, being the extracting, or finding


the roots of any given powers, or numbers.
The Root of any number, or power, is such a number as being multiplied
into itself a certain number of times, will produce that power.
Thus, 2 is the square root, or 2nd root of 4, because, 22 = 2 × 2 = 4;
and 3 is the cube root, or third root of 27. But there are many numbers of
which a proposed root can never be exactly found; by means of decimals,
however, the root may be very nearly ascertained.
Any power of a given number, or root, may be found exactly by
multiplying the number continually into itself.
Those roots which only approximate are called Surd-roots; but those
which can be found, quite exactly, are called Rational-roots. Thus, the
square root of 3 is a surd root, but the square root of 4 is a rational root,
being equal to 2; also the cube root of 8 is rational, being equal to 2, but
the cube root of 9 is surd, or irrational. Roots are sometimes denoted by
writing the character √ before the power with the index of the root
against it. Thus, the 3rd, or cube root of 20 is expressed by ∛20. When
the power is expressed by several numbers with the sign + or - between
them, a line is drawn from the top of the sign over all the parts of it; thus
the cube (or third) root of 45 - 12 is ∛45 - 12 or thus ∛(45 - 12).

TO EXTRACT THE SQUARE ROOT.

Rule.—Divide the given number into periods of two figures each, by


setting a point over the place of units, and another over the place of
hundreds, and so on over every second figure, both to the left hand in
integers, and right hand in decimals. Find the greatest square in the first
period on the left hand, and set its root on the right hand of the given
number, after the manner of the quotient figure in division. Subtract the
square thus found from the said period, and to the remainder annex the
two figures of the next following period for a dividend. Double[45] the root
above-mentioned for a divisor, and find how often it is contained in the
said dividend, exclusive of its right-hand figure; and set that quotient
figure both in the quotient, and divisor. Multiply the whole augmented
divisor by this last quotient figure, and subtract the product from the said
dividend, bringing down to it the next period of the given number, for a
new dividend. Repeat the same process over again—viz., find another new
divisor, by doubling all the figures now found in the root; from which, and
the last dividend find the next figure of the root as before; and so on
through all the periods to the last.

To extract the square root of a fraction, or mixed number.


Reduce the fraction to a decimal, and extract its root.
Mixed numbers may be either reduced to improper fractions, and the
root extracted; or the fraction may be reduced to a decimal, then joined to
the integer, and the root of the whole extracted.
Example.—To find the square root of 29506624.
29506624 ( 5432 The Root.
25
104 450
4 416
1083 3466
3 3249
10862 21724
2 21724

TO EXTRACT THE CUBE ROOT.

Rule 1.—By trials, or by the table of roots (vide page 280), take the
nearest rational cube to the given number, whether it be greater, or less,
and call it the assumed cube.
2.—Then (by the Rule of Three),
As the sum of the given number, and double the assumed cube, is to
the sum of the assumed cube, and double the given number, so is the root
of the assumed cube, to the root required, nearly.
3.—Or as the first sum,
is to the difference of the given, and assumed cube,
so is the assumed root,
to the difference of the roots, nearly.
4.—Again, by using, in like manner, the cube of the root last found as a
new assumed cube, another root will be obtained still nearer. Repeat this
operation as often as necessary, using always the cube of the last-found
root, for the assumed root.
Example.—To find the cube root of 21035·8.
By trials it will be found first, that the root lies between 20, and 30;
and, secondly, between 27, and 28. Taking, therefore, 27, its cube is
19683, which will be the assumed cube. Then by No. 2 of the Rule
19683 21035·8
2 2
39366 42071·6
21035·8 19683·
As 60401·8 : 61754·6 :: 27 : 27·6047 the Root, nearly.
Again for a second operation, the cube of this root is
21035·318645155832, and the process by No. 3 of the
Rule will be
21035·318645, &c.
2
42070·637290 21035·8
21035·8 21035·318645, &c.
As 63106·43729 : diff. ·481355 :: 27·6047 :
: the diff. ·000210560
consequently the root required is 27·604910560
TABLE OF SQUARES, CUBES, AND ROOTS.

Cube Cube
No. Sqr. Cube. Sqr. root. No. Sqr. Cube. Sqr. root.
root. root.

1 1 1 1·0000000 1·000000 51 2601 132651 7·1414284 3·708430


2 4 8 1·4142136 1·259921 52 2704 140608 7·2111026 3·732511
3 9 27 1·7320508 1·442250 53 2809 148877 7·2801099 3·756286
4 16 64 2·0000000 1·587401 54 2916 157464 7·3484692 3·779763
5 25 125 2·2360680 1·709976 55 3025 166375 7·4161985 3·802953
6 36 216 2·4494897 1·817121 56 3136 175616 7·4893148 3·825862
7 49 343 2·6457513 1·912933 57 3249 185193 7·5498344 3·848501
8 64 512 2·8284271 2·000000 58 3364 195112 7·6157731 3·870877
9 81 729 3·0000000 2·080084 59 3481 205379 7·6811457 3·892996
10 100 1000 3·1622777 2·154435 60 3600 216000 7·7459667 3·914867
11 121 1331 3·3166248 2·223980 61 3721 226981 7·8102497 3·936497
12 144 1728 3·4641016 2·289428 62 3844 238328 7·8740079 3·957892
13 169 2197 3·6055513 2·351335 63 3969 250047 7·9372539 3·979057
14 196 2744 3·7416574 2·410142 64 4096 262144 8·0000000 4·000000
15 225 3375 3·8729833 2·466212 65 4225 274625 8·0622577 4·020726
16 256 4096 4·0000000 2·519842 66 4356 287496 8·1240384 4·041240
17 289 4913 4·1231056 2·571282 67 4489 300763 8·1853528 4·061548
18 324 5832 4·2426407 2·620741 68 4624 314432 8·2462113 4·081656
19 361 6859 4·3588989 2·668402 69 4761 328509 8·3066239 4·101566
20 400 8000 4·4721360 2·714418 70 4900 343000 8·3666003 4·121285
21 441 9261 4·5825757 2·758923 71 5041 357911 8·4261498 4·140818
22 484 10648 4·6904158 2·802039 72 5184 373248 8·4852814 4·160168
23 529 12167 4·7958315 2·843867 73 5329 389017 8·5440037 4·179339
24 576 13824 4·8989795 2·884499 74 5476 405224 8·6023253 4·198336
25 625 15625 5·0000000 2·924018 75 5625 421875 8·6602540 4·217163
26 676 17576 5·0990195 2·962496 76 5776 438976 8·7177979 4·235824
27 729 19683 5·1961524 3·000000 77 5929 456533 8·7749644 4·254321
28 784 21952 5·2915026 3·036589 78 6084 474552 8·8317609 4·272659
29 841 24389 5·3851648 3·072317 79 6241 493039 8·8881944 4·290841
30 900 27000 5·4772256 3·107232 80 6400 512000 8·9442719 4·308870
31 961 29791 5·5677644 3·141381 81 6561 531441 9·0000000 4·326749
32 1024 32768 5·6568542 3·174802 82 6724 551368 9·0553851 4·344481
33 1089 35937 5·7445626 3·207534 83 6889 571787 9·1104336 4·362071
34 1156 39304 5·8309519 3·239612 84 7056 592704 9·1651514 4·379519
35 1225 42875 5·9160798 3·271066 85 7225 614125 9·2195445 4·396830
36 1296 46656 6·0000000 3·301927 86 7396 636056 9·2736185 4·414005
37 1369 50653 6·0827625 3·332222 87 7569 658503 9·3273791 4·431047
38 1444 54872 6·1644140 3·361975 88 7744 681472 9·3808315 4·447960
39 1521 59319 6·2449980 3·391211 89 7921 704969 9·4339811 4·464745
40 1600 64000 6·3245553 3·419952 90 8100 729000 9·4868330 4·481405
41 1681 68921 6·4031242 3·448217 91 8281 753571 9·5393920 4·497942
42 1764 74088 6·4807407 3·476027 92 8464 778688 9·5916630 4·514357
43 1849 79507 6·5574385 3·503398 93 8649 804357 9·6436508 4·530655
44 1936 85184 6·6332496 3·530348 94 8836 830584 9·6953597 4·546836
45 2025 91125 6·7082039 3·556893 95 9025 857375 9·7467943 4·562903
46 2116 97336 6·7823300 3·583048 96 9216 884736 9·7979590 4·578857
47 2209 103823 6·8556546 3·608826 97 9409 912673 9·8488578 4·594701
48 2304 110592 6·9282032 3·634241 98 9604 941192 9·8994949 4·610436
49 2401 117649 7·0000000 3·659306 99 9801 970299 9·9498744 4·626065
50 2500 125000 7·0170678 3·684031 100 10000 1000000 10·0000000 4·641589

PILING OF SHOT, AND SHELL.

Shot, and shells, are usually piled in horizontal courses, the base
being either an equilateral triangle, a square, or a rectangle. The
triangular, and square piles terminate each in a single ball, but the
rectangular pile finishes in a row of balls.

To find the number of balls in a complete pile.


Rule.—Add the three parallel edges together; then one-third of the
product of that sum, and of the number of balls in the triangular
face, will be the number sought.
Note 1.—The parallel edges in a rectangular pile are the two rows
in length at the base, and the upper ridge. In the square pile the
same, except that the upper row is only a single ball. In the
triangular pile, one side of the base, the single ball at top, and that
at the back, are considered the parallel edges.
Note 2.—The number of balls in the triangular face is found by
multiplying half the number in the breadth at the base, by the
number in the breadth at the base plus 1.
Note 3.—In all piles the breadth of the bottom is equal to the
number of courses. In the oblong pile, the top row is one more than
the difference between the length, and breadth of the bottom.
Example.—To find the shot in a triangular pile, the bottom row
consisting of 12 shot.

Parallel { 12
edges. { 1 12 ÷ 2 = 6
{ 1 12 + 1 = 13
Triangular face 78
3) 14 4⅔
4⅔ 312
52
Answer 364

Example.—To find the shot in a square pile, the bottom row


consisting of 12 shot.

12
1 12 ÷ 2 = 6
1 12 + 1 = 13
78
3) 25 8⅓
8⅓ 624
26
Answer 650
Example.—To find the shot in an oblong pile, whose base consists
of 18 shot in length, and 12 in breadth.

18 18 - 12 = 6
18 1
7 7
3) 43
14⅓ 12 ÷ 2 = 6
12 + 1 = 13
78
14⅓
312
78
26
Answer 1118

Triangular pile.
Rule.—Multiply the base by the base plus 1, this product by the
base plus 2, and divide by 6.

Square pile.
Rule.—Multiply the bottom row by the bottom row plus 1, and this
product by twice the bottom row plus 1, and divide by 6.

Rectangular, or oblong pile.


Rule.—Multiply the breadth of the base by itself plus 1; and this
product by three times the length of the base plus 1, minus the
breadth of the base, and divide by 6.
In the following formulæ let the letter (L) denote the number in
the bottom row, or the length; and (B) the breadth of the lowest
course.

Triangular pile L × (L + 1) × (L + 2)
6
Square pile L × (L + 1) × (2L + 1)
6
Oblong pile B × (B + 1) × (3L + 1 - B)
6

The number of shot in any pile,


(whose base does not exceed 21) may readily be ascertained by
referring to the following Table, page 284.
For the square pile.—Look for the number of shot in the base, in
the first vertical column on the left hand, and also in the diagonal
column; and at their angle of meeting will be found the content
required.
Thus 20 base gives 2870.
For the triangular pile.—Look for the number in the base row in
the diagonal column, and opposite to it will be found the content.
Thus 18 base gives 1140.
For the oblong pile.—Look for the number in the length of the
base in the vertical column, and the breadth of the base in the
diagonal column, and at their angle of meeting will be found the
content required.
Thus 17 length, and 12 breadth, gives 1040.

To find the number of balls in an incomplete pile.


Compute the number in the pile considered as complete; also the
number in the upper pile, or part wanting; and the difference
between the two piles thus found will be the number in the
frustrum, or incomplete pile.
Table for computing the Content of any Pile, whose base row does not exceed 21 balls.

1 2 4
2 5 3 10
3 8 14 4 20
4 11 20 30 5 35
5 14 26 40 55 6 56
6 17 32 50 70 91 7 84
7 20 38 60 85 112 140 8 120
8 23 44 70 100 133 168 204 9 165
9 26 50 80 115 154 196 240 285 10 220
10 29 56 90 130 175 224 276 330 385 11 286
11 32 62 100 145 196 252 312 375 440 506 12 364
12 35 68 110 160 217 280 348 420 495 572 650 13 455
13 38 74 120 175 238 308 384 465 550 638 728 819 14 560
14 41 80 130 190 259 336 420 510 605 704 806 910 1015 15 680
15 44 86 140 205 280 364 456 555 660 770 884 1001 1120 1240 16 816
16 47 92 150 220 301 392 492 600 715 836 962 1092 1225 1360 1496 17 969
17 50 98 160 235 322 420 528 645 770 902 1040 1183 1330 1480 1632 1785 18 1140
18 53 104 170 250 343 448 564 690 825 968 1118 1274 1435 1600 1768 1938 2109 19 1330
19 56 110 180 265 364 476 600 735 880 1034 1196 1365 1540 1720 1904 2091 2280 2470 20 1540
20 59 116 190 280 385 504 636 780 935 1100 1274 1456 1645 1840 2040 2244 2451 2660 2870 21 1771
21 62 122 200 295 406 532 672 825 990 1166 1352 1547 1750 1960 2176 2397 2622 2850 3080 3311 22 2024

CORDAGE.

Ropes, cables, and all other descriptions of cordage are distinguished by their
circumference, thus a two-inch rope means a rope two inches in circumference.

To find the weight of a rope.


First method.—Multiply the length in fathoms by the square of the
circumference, and divide the product by 480 for the weight in cwts.
Example.—Required the weight of 110 fathoms of 3-inch rope.
3 × 3 × 110 = 990, which divided by 480, gives 2 cwt. 7 lb. Weight required.
Second method.—Divide the square of the circumference by 4, the quotient will
give the weight, in pounds, per fathom.
Example.—What is the weight of a 3-inch rope per fathom?
32 ÷ 4 = 2¼ lb. Weight required.

To find the strength of a rope, or the weight it will support.


First method.—Square the circumference, and divide by 5, for the number of
tons which it will bear suspended from it.[46]
Example.—What weight will 3-inch rope of the best description support?
(3 × 3)
= 9/5 = 1⅘ ton, or 4030 lb. Weight required.
5

Second method.—Multiply the square of the circumference by 2, the product will


give the practical weight in cwts. that may be lifted by it, or about half the
breaking weight.
Example.—What number of cwts. may be lifted by a 3-inch rope?
32 × 2 = 18 cwts. Weight required.
The strain, in pounds, a rope will bear safely = girt2 × 200}
nearly.
” ” a cable ” ” = girt2 × 120}

CHAINS.

To find the weight of chains.


The square of the diameter of the link, measured in eighths of inches, will give
the weight of the chain, per fathom, in pounds.
Example.—What is the weight per fathom of a ¾-inch chain?
¾-inch = 6; 62 = 36 lb. Weight per fathom.
8

Or, the weight per foot of the chain, multiplied by 24, will give the weight per
fathom of the chain, nearly. A chain cable with a stay across the links will weigh
about one-twelfth more than the foregoing examples.

To find the weight that may be safely lifted by a chain.


Divide the square of the diameter of the links, taken in eighths of an inch by 8,
and the quotient will give the number of tons that may be lifted by the chain.
Example.—What number of tons will a chain made of ¾-inch iron carry with
safety?

¾-inch = 6 62 = 36 36
= 4½ tons. Weight required.
8 8

The safe strain is equal to about 8 tons, per square inch, of the iron of which the
chain is made.
The stay across the link of a chain increases its strength about one-sixth.
When the chain is of great length, a deduction, from the above rules, must be
allowed for the weight of it.
IRON RODS.

To find the weight of round iron rods.


Divide the square of the diameter, in quarter inches, by 2, and the quotient will
give the weight in pounds, per yard.
Example.—What is the weight of a yard of 1-inch round iron.
16
1 inch = 4 quarters 42 = 16 = 8 lb. Weight required.
2

To find the weight of square rods.


The weight of round rods, of similar diameter, divided by ·7854 will give the
weight of the square rods.

To find the weight that may be sustained, or lifted by round iron rods.
Find the weight in pounds, per yard; two-thirds of which will give the safe load,
in tons.
A round iron rod of average quality of iron, one inch in diameter, will be torn
asunder by 16 tons; it will be perceptibly damaged by half this strain, or 8 tons; its
safe load will be one-third, or 5·33 tons.

TIMBER.

To find the area, or superficial content of a plank.


Multiply the length by the mean breadth.[47]
Example.—Required the content of a board whose length is 11 feet 2 inches,
and breadth 1 foot 10 inches
ft. in. ft. in. ft. in.
11 2 × 1 10 = 20 5. Content required.

To find the solid content of squared, or four-sided timber.


Multiply the mean breadth by the mean thickness, and the product by the
length, for the content, nearly.
Note 1.—If the tree taper regularly from the one end to the other, either take
the mean breadth, and thickness in the middle, or take the dimensions at the two
ends, and half their sum will be the mean dimensions; which, multiplied as by the
above rule, will give the content, nearly.
Note 2.—If the piece do not taper regularly, take several different dimensions,
add them all together, and divide their sum by the number of them, for the mean
dimensions.
Example.—Required the content of a piece of timber 16 feet long, and side of
square 14 inches.
ft. in. ft. in. ft. ft. in.
1 2 × 1 2 × 16 = 21 9. Content required.

To find the solidity of round, or unsquared timber.


1. Multiply the square of the quarter girt (or the square of ¼ of the mean
circumference), by the length, for the content.
Note.—When the tree is tapering, take the mean dimensions, either by girting it
in the middle for the mean girt, or at the two ends, taking half the sum of the two;
or by girting it in several places, then adding all the girts together, and dividing the
sum by the number of them for the mean girt. But when the tree is very irregular,
divide it into several lengths, and find the content of each part separately.
Example.—Required the content of a tree, whose mean girt is 3·15 feet, and
length 14½ feet.
3.15
= ·7875 ·7875 × ·7875 = ·62015625.
4

·62015 × 14·5 = 8·9922 feet of solid timber. The content required.


2. Find the mean area of a round tree, and multiply it by the length for the
content.

To find the weight of a tree.


Find its content in feet, and multiply that by the specific gravity of the wood.
(Vide Gravity, and Table of Specific Gravities. Page 318.)
Example.—Required the weight of an elm-tree; whose mean girt is 5 feet, and
length 60 feet.
5
= 1·25 1·25 × 1·25 = 1·5625.
4

1·5625 × 60 = 93·75. Content in feet.


TONNAGE.

Table of Tonnage, and Weight of one of the following


Carriages, Carts, Waggons, Gyns, &c., used in land service.

Carriages. Tonnage. Weight.


Tons. ft. Cwt.qrs.lb. With
{ 24
6 0 34 0 22 bullock
pounder
{ 8 inch 6 0 34 2 12 pole and
{ 18
*For Iron 4 39 27 2 9 chain,
pounder
Ordnance. { 12 ” 21 cwt. 4 7 18 3 24 weighing
{ 10 2 qrs. 19
{ Howitzer 6 17 39 0 9
inch lb.
{ 8 ” 5 37 33 2 0

{ 12
5 33 22 0 10
pounder
{ 9 ” 5 1 20 2 14
*For Brass { 6 ” 4 21 17 3 5
Ordnance. { { 32 pr. 5 29 23 3 13
{ Howitzer { 24 ” 5 6 21 0 17
{ { 12 ” 4 21 18 3 14

For all
*Ammunition waggon 5 36 20 0 3
natures.
*Forge 5 38 19 1 0
*Store-waggon (without spare
5 11 18 1 10
wheel)
*Small arm ammunition waggon 4 36 14 2 16
{ 12
7 33 20 2 8
*Rocket pounder
{6” 5 17 20 1 20
{ Large 3 30 42 2 13
*Pontoon
{ Small 22 2 5
Garrison, wood, common standing for
1 8 8 0 7
32 pounder of 25 cwt.
* Travelling complete.

Tons. ft. Cwt.qrs.lb.


Capstan, crab 0 31 3 3 26
{ Forge, cavalry 4 32 11 2 3
{ Hand 1 10 4 3 4
{ Hospital, conveyance 3 16 10 2 20
Carts { Sling 3 38 16 1 17
{ Store 3 16 9 1 0
{ French 1 32 5 2 13
Drugs { Large 2 7 17 1 24
{ Small 0 29 5 0 4
Gyns, { Large 1 23 9 2 22
Triangle { Small 1 2 7 3 3
{ For 32 pounder
{ Madras 0 26 6 0 12 Fir.
garrison carriage
{ For traversing
Platform. { Madras carriage 1 23 14 2 0 Teak.
with tail-piece
{ Mortar, Alderson’s pattern 0 30 8 1 4

Portable forge, and pack saddle, in wooden


0 17 2 1 3
case

{ Flanders 5 0 16 1 25
Waggons { Platform 3 16 21 3 18
{ Sling 8 11 31 3 26
Waggons, hospital, Mr. Holmes’ {Large 9 10 21 0 0
pattern {Small. 6 30 18 0 4

The calculation of tonnage for baggage, stores, &c., is by


measurement: a Ton, consisting of 40 cubic feet; but metals, and

You might also like