0%

This book will teach you how to solve engineering problems with Python. The “hardcore” approach means that you will learn to get the correct results by coding everything from scratch. Forget relying on third-party software – there are no shortcuts on the path to proficiency. Instead, using familiar concepts from linear algebra, geometry and physics, you’ll write your own libraries, draw your own primitives, and build your own applications.

Author Angel Sola covers core programming techniques mechanical engineers need to know, with a focus on high-quality code and automated unit testing for error-free implementations. After basic primers on Python and using the command line, you’ll quickly develop a geometry toolbox, filling it with lines and shapes for diagramming problems. As your understanding grows chapter-by-chapter, you’ll create vector graphics and animations for dynamic simulations; you’ll code algorithms that can do complex numerical computations; and you’ll put all of this knowledge together to build a complete structural analysis application that solves a 2D truss problem – similar to the software projects conducted by real-world mechanical engineers.

You'll learn:

•How to use geometric primitives, like points and polygons, and implement matrices
•Best practices for clean code, including unit testing, encapsulation, and expressive names
•Processes for drawing images to the screen and creating animations inside Tkinter’s Canvas widget
•How to write programs that read from a file, parse the data, and produce vector images
•Numerical methods for solving large systems of linear equations, like the Cholesky decomposition algorithm

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. About the Author
  6. BRIEF CONTENTS
  7. CONTENTS IN DETAIL
  8. ACKNOWLEDGMENTS
  9. INTRODUCTION
    1. Who This Book Is For
    2. What You’ll Learn
    3. About This Book
    4. Setting Up Your Environment
    5. PyCharm Introduction
    6. Summary
  10. PART I BASICS
  11. 1 A SHORT PYTHON PRIMER
    1. Python Packages and Modules
    2. Running Files
    3. Importing Code
    4. Documenting the Code with Docstrings
    5. Collections in Python
    6. Destructuring
    7. Summary
  12. 2 TWO PYTHON PARADIGMS
    1. Functional Programming
    2. Object-Oriented Programming
    3. Type Hints
    4. Summary
  13. 3 THE COMMAND LINE
    1. Unix and Windows
    2. Finding Your Shell
    3. Files and Directories
    4. Running Python Scripts
    5. Passing Arguments to the Script
    6. Standard Input and Output
    7. Using PyCharm’s Python Console
    8. Summary
  14. PART II 2D GEOMETRY
  15. 4 POINTS AND VECTORS
    1. The Point Class
    2. The Vector Class
    3. Completing Our Classes
    4. Unit Testing
    5. Summary
  16. 5 LINES AND SEGMENTS
    1. Segment Class
    2. Line Class
    3. Segment’s Bisector
    4. Summary
  17. 6 POLYGONS
    1. Polygon Class
    2. Circle Class
    3. Rect Class
    4. Summary
  18. 7 AFFINE TRANSFORMATIONS
    1. Affine Transformations
    2. The Affine Transformation Class
    3. Interpolating Transformations
    4. Geom2D Final Touches
    5. Summary
  19. PART III GRAPHICS AND SIMULATIONS
  20. 8 DRAWING VECTOR IMAGES
    1. Bitmaps and Vector Images
    2. The SVG Format
    3. The svg Package
    4. The SVG Primitives
    5. Primitives Result
    6. Package Imports
    7. Summary
  21. 9 BUILDING A CIRCLE FROM THREE POINTS
    1. Application Architecture
    2. Setup
    3. Reading the Input and Configuration Files
    4. Problem Model and Resolution
    5. Generating Output
    6. Distributing Our Application
    7. Summary
  22. 10 GRAPHICAL USER INTERFACES AND THE CANVAS
    1. Tkinter
    2. Drawing Our Geometric Primitives
    3. Summary
  23. 11 ANIMATIONS, SIMULATIONS, AND THE TIME LOOP
    1. Defining Terms
    2. What Is the Time Loop?
    3. Our First Animation
    4. Abstracting the Main Loop Function
    5. Refactoring Our Simulation
    6. Cleaning Up the Module
    7. Summary
  24. 12 ANIMATING AFFINE TRANSFORMATIONS
    1. Application Architecture and Visibility Diagrams
    2. Setting Up
    3. Reading the Configuration File
    4. Reading Input
    5. Running the Simulation
    6. Summary
  25. PART IV SYSTEMS OF EQUATIONS
  26. 13 MATRICES AND VECTORS
    1. List Utils
    2. Setup
    3. Vectors
    4. Matrices
    5. Summary
  27. 14 LINEAR EQUATIONS
    1. Systems of Linear Equations
    2. Numerical Methods
    3. Cholesky Decomposition
    4. Summary
  28. PART V TRUSS STRUCTURES
  29. 15 STRUCTURAL MODELS
    1. Solving Structural Problems
    2. Structural Member Internal Forces
    3. Tension and Compression
    4. Plane Trusses
    5. Two-Force Members
    6. Stiffness Matrices in Global Coordinates
    7. Original Structure Model
    8. The Structure Solution Model
    9. Summary
  30. 16 STRUCTURE RESOLUTION
    1. Structure Resolution
    2. Advanced Unit Testing: Test Doubles
    3. Testing the Structure Solution Class
    4. Testing the Structure Resolution Process
    5. Summary
  31. 17 READING INPUT FROM A FILE
    1. Defining the Input Format
    2. Finding the Regular Expressions
    3. Setup
    4. Parsing Nodes
    5. Parsing Bars
    6. Parsing Loads
    7. Parsing the Structure
    8. Summary
  32. 18 PRODUCING AN SVG IMAGE AND TEXT FILE
    1. Setup
    2. From Structure Solution to SVG
    3. From Structure Solution to Text
    4. Summary
  33. 19 ASSEMBLING OUR APPLICATION
    1. A General Overview
    2. Setup
    3. Input Arguments
    4. Generating the Output
    5. The Main Script
    6. Trying the App
    7. Summary
  34. BIBLIOGRAPHY
  35. INDEX
3.238.107.238