Contents in Detail
HARDCORE PROGRAMMING FOR MECHANICAL ENGINEERS
Build Engineering Applications from Scratch
by ngel Sola Orbaiceta
San Francisco
HARDCORE PROGRAMMING FOR MECHANICAL ENGINEERS. Copyright 2021 by ngel Sola Orbaiceta
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.
ISBN-13: 978-1-7185-0078-5 (print)
ISBN-13: 978-1-7185-0079-2 (ebook)
Publisher: Bill Pollock
Production Manager: Rachel Monaghan
Production Editor: Katrina Taylor
Developmental Editor: Alex Freed
Cover Illustrator: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Peter Kazarinoff
Copyeditor: Kim Wimpsett
Proofreader: Lisa Devoto Farrell
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900; fax: 415.863.9950;
Library of Congress Control Number: 2021930213
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.
[S]
To my wife Jen, the person I most admire.
About the Author
ngel Sola majored in industrial engineering with a focus in mechanics from the Public University of Navarra. Hes a self-taught programmer, who has been working in the software industry since 2013. He currently works at Glovo (https://glovoapp.com/), a thriving start-up in the heart of Barcelona. In his spare time, he develops his own applications (like InkStructure, which solves 2D structure problems), brews beer, and cooks food from around the world.
About the Technical Reviewer
Peter D. Kazarinoff, PhD, is a faculty member in Engineering and Engineering Technology at Portland Community College. Peter earned a PhD in materials science and engineering from the University of Washington and a BA from Cornell University. He teaches courses in engineering programming, mechanical engineering, and material science. Peter lives in Portland, Oregon with his wife and two inquisitive daughters. He is the author of the book Problem Solving with Python and blogs at pythonforundergradengineers.com.
CONTENTS IN DETAIL
PART I
BASICS
1
A SHORT PYTHON PRIMER
2
TWO PYTHON PARADIGMS
3
THE COMMAND LINE
PART II
2D GEOMETRY
4
POINTS AND VECTORS
5
LINES AND SEGMENTS
6
POLYGONS
7
AFFINE TRANSFORMATIONS
PART III
GRAPHICS AND SIMULATIONS
8
DRAWING VECTOR IMAGES
9
BUILDING A CIRCLE FROM THREE POINTS
10
GRAPHICAL USER INTERFACES AND THE CANVAS
11
ANIMATIONS, SIMULATIONS, AND THE TIME LOOP
12
ANIMATING AFFINE TRANSFORMATIONS
PART IV
SYSTEMS OF EQUATIONS
13
MATRICES AND VECTORS
14
LINEAR EQUATIONS
PART V
TRUSS STRUCTURES
15
STRUCTURAL MODELS
16
STRUCTURE RESOLUTION
17
READING INPUT FROM A FILE
18
PRODUCING AN SVG IMAGE AND TEXT FILE
19
ASSEMBLING OUR APPLICATION
ACKNOWLEDGMENTS
The person I want to thank most is my wife Jen. Without her emotional support, this book would have been impossible to finish.
Second, I want to thank my parents, Angel and Raquel. They taught me the importance of hard work and paying attention to the details. Those lessons are some of the most valuable we can learn from our parents. I couldnt have had better mentors.
Big thanks to Bill Pollock, who believed in this project and gave me the opportunity to make it happen. Im also very thankful to Alex Freed, the editor for the book. Without her edits, the books quality wouldnt be half of what it is. Her editorial skills have made a huge difference. Im very thankful to Katrina Taylor as well, who made a great job reviewing unifying the language of the book and moving it to production. I want to also say thanks to the team at No Starch Press who were involved in producing this book; working with them has been a very pleasurable experience. And I cant forget about Gina Redman, who I want to thank for the books cover illustration.
Lastly, I want to thank Peter Kazarinoff for his invaluable technical feedback. A lot of his advice was crucial to shaping the code and explanations in the book.
INTRODUCTION
Knowing how to write code empowers you to solve complex problems. By harnessing the capabilities of modern CPUs, which can accomplish billions of operations per second, we can quickly and correctly work out the solutions to difficult problems.
This is a book about solving engineering problems with Python. Well learn how to code geometric primitives that will serve as the basis of more complex operations, how to read and write from files, how to create vector images and animated sequences to present the results, and how to solve large systems of linear equations. Finally, well put all this knowledge together to build an application that solves truss structure problems.
Who This Book Is For
This book is targeted at engineering students, graduated engineers, or just about any person with a technical background who wants to learn how to write applications to solve engineering problems.
A background in math and mechanics is a must. Well be using concepts from linear algebra, 2D geometry, and physics. Well also use some mechanics of materials and numerical methods, which are subjects common to many engineering degrees. We wont go too far into these topics to allow a larger number of readers to find the material of the book useful. The techniques learned in this book can later be used to solve problems that involve more complex concepts.
To follow along, youll need to have some coding skills and basic Python knowledge. This is not an introductory book to programming; there are lots of other good books covering that. I can recommend