Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Cover
Title
Copyright
Dedication
Contents at a Glance
Contents
About the Authors
About the Technical Reviewer
About the Cover Image Artist
Acknowledgments
Preface
What this book will (and won't) teach you
Overview of this book
Source code and examples
Part I: The Basics
Chapter 1: Introduction to Physics Programming
Why model real physics?
Creating realistic animation effects
Creating realistic games
Building simulations and models
Generating art from code
Can't I just use a physics engine?
What is physics?
Everything behaves according to the laws of physics
The laws can be written as math equations
Predicting motion
Programming physics
The difference between animation and simulation
The laws of physics are simple
Hence, they can be readily coded up!
The four steps for programming physics
A simple example
A bouncing ball: the physics
Coding up a bouncing ball in 2D
Summary
Chapter 2: Selected ActionScript 3.0 Topics
ActionScript 3.0 classes
Classes and objects
Structure of an AS3.0 class
Functions, methods and constructors
Properties
Static methods and properties
Inheritance
ActionScript 3.0 language basics
Variables and constants
Data types
Operators
Math
Logic
Loops
Events in ActionScript 3.0
Event listeners and handlers
Events and user interaction
Drag and drop
The Flash coordinate system
2D coordinates
3D in Flash
The Flash drawing API
Drawing lines and curves
Creating fills and gradients
Example: Bouncing ball in a box
Producing animation using code
Using the built-in frame stepping as a clock
Using the Timer class
Using getTimer() to compute elapsed time
Precalculating motion
Collision detection
Using the hitTestObject() method
Using the hitTestPoint() method
Distance-based collision detection
Advanced collision detection
Summary
Chapter 3: Some Math Background
Coordinates and simple graphs
Building a plotter: the Graph class
Plotting functions using the Graph class
Straight lines
Polynomial curves
Things that grow and decay: exponential and log functions
Making an object move along a curve
Distance between two points
Basic trigonometry
Degrees and radians
The sine function
The cosine function
The tangent function
The inverse trig functions
Using trig functions for animation
Vectors and basic vector algebra
What are vectors?
Vectors and scalars
Adding and subtracting vectors
Resolving vectors: vector components
Multiplying vectors: Scalar or dot product
Multiplying vectors: Vector or cross product
Building a Vector class with vector algebra
Simple calculus ideas
Slope of a line: gradient
Rates of change: derivatives
Doing sums: integrals
Summary
Chapter 4: Basic Physics Concepts
General physics concepts and notation
Physical quantities and units
Scientific notation
Things: particles and other objects in physics
What is a particle?
Particle properties
Building a Particle class
Moving particles: the Mover class
Extending the Particle class
Describing motion: kinematics
Concepts: displacement, velocity, speed, acceleration
Combining vector quantities
Describing motion using graphs
Equations of motion for uniform acceleration
Applying the equations to projectile motion
More motion-related concepts: inertia, mass, and momentum
Predicting motion: forces and dynamics
The cause of motion: forces
The relationship between force, mass, and acceleration
Types of forces
Combining forces: force diagrams and resultant force
Forces in equilibrium
An example: object falling under gravity and drag
Energy concepts
The notion of work in physics
The capacity to do work: energy
Energy transfer, conversion, and conservation
Potential and kinetic energy
Power
Example: a rudimentary “car” simulation
Summary
Part II: Particles, Forces, and Motion
Chapter 5: The Laws Governing Motion
Newton’s laws of motion
Newton’s first law of motion (N1)
Newton’s second law of motion (N2)
Newton’s third law of motion (N3)
Applying Newton’s laws
General method for applying F = ma
The Forcer class
The Forces class
A simple example: projectile with drag
A more complicated example: floating ball
Newton’s second law as a differential equation
Taking a deeper look at F = ma
An example: Fall under gravity and drag revisited
The principle of energy conservation
Conservation of mechanical energy
An example: Energy changes in a projectile
The principle of momentum conservation
Example: 1D elastic collision between two particles
Laws governing rotational motion
Summary
Chapter 6: Gravity, Orbits, and Rockets
Gravity
Gravity, weight, and mass
Newton’s universal law of gravitation
Creating the gravity function
Orbits
Orbiter class
Escape velocity
Two-body motion
Local gravity
The force of gravity near the Earth’s surface
Variation of gravity with height
Gravity on other celestial bodies
Rockets
It is rocket science!
Modeling the thrust of a rocket
Building a rocket simulation
Summary
Chapter 7: Contact and Fluid Forces
Contact forces
Normal contact forces
Tension and compression
Friction
Example: Sliding down a slope
Pressure
The meaning of pressure
Density
Variation of pressure with depth in a fluid
Static and dynamic pressure
Upthrust (buoyancy)
Archimedes's Principle
Apparent weight
Submerged objects
Floating objects
Example: Balloon
Drag
Drag law for low velocities
Drag law for high velocities
Which drag law should I use?
Adding drag to the balloon simulation
Example: Floating ball
Terminal velocity
Example: Parachute
Lift
Lift coefficients
Example: An airplane
Wind and turbulence
Force due to the wind
Wind and drag
Steady and turbulent flow
Example: Air bubbles in a steady wind
Modeling turbulence
Summary
Chapter 8: Restoring Forces: Springs and Oscillations
Springs and oscillations: Basic concepts
Spring-like motion
Restoring force, damping, and forcing
Hooke’s law
Free oscillations
The spring force function
Creating a basic oscillator
Simple harmonic motion
Oscillations and numerical accuracy
Damped oscillations
Damping force
The effect of damping on oscillations
Analytical solutions for oscillations with damping
Forced oscillations
Driving forces
Example: A periodic driving force
Example: A random driving force
Gravity as a driving force: bungee jumping
Example: Driving force by user interaction
Coupled oscillators: Multiple springs and objects
Example: A chain of objects connected by springs
Summary
Chapter 9: Centripetal Forces: Rotational Motion
Kinematics of uniform circular motion
Angular displacement
Angular velocity
Angular acceleration
Period, frequency, and angular velocity
Relation between angular velocity and linear velocity
Example: A rolling wheel
Particles with spin
Example: Satellite around a rotating Earth
Centripetal acceleration and centripetal force
Centripetal acceleration
Centripetal acceleration, velocity and angular velocity
Centripetal force
Common misconceptions about centripetal force
Example: Revisiting the satellite animation
Example: Circular orbits with gravitational force
Example: Car moving around a bend
Non-uniform circular motion
Tangential force and acceleration
Example: A simple pendulum
Summary
Chapter 10: Long-Range Forces
Particle interactions and force fields
Interaction at a distance
From particle interactions to force fields
Newtonian gravitation
Gravitational field due to a particle
Gravity with multiple orbiters
Gravity with multiple attractors
Particle trajectories in a gravity field
Building a simple black hole game
Electrostatic force
Electric charge
Coulomb's law of electrostatics
Charged particle attraction and repulsion
Electric fields
Electromagnetic force
Magnetic fields and forces
The Lorentz force law
Other force laws
Central forces
Gravity with a spring force law?
Multiple attractors with different laws of gravity
Summary
Part III: Multi-particle and Extended Systems
Chapter 11: Collisions
Collisions and their modeling
Bouncing off horizontal or vertical walls
Elastic bouncing
Implementing energy loss due to bouncing
Bouncing off inclined walls
Collision detection
Repositioning the particle
Calculating the new velocity
Velocity correction just before collision
An example of a ball bouncing off an inclined wall
Example of ball bouncing off multiple inclined walls
Collisions between particles in 1D
Repositioning the particles
Elastic collisions
Inelastic collisions
Collisions between particles in 2D
An example: 2D collisions between two particles
Example: multiple particle collisions
Example: multiple particle collisions with bouncing
Summary
Chapter 12: Particle Systems
Introduction to particle system modeling
Creating animated effects using particles
A simple example: splash effect with particles
Creating a particle emitter
Creating a smoke effect
Creating a fire effect
Creating fireworks
Particle animations with long-range forces
Particle paths in a force field
Building a wormhole
Interacting particle systems
Multiple particles under mutual gravity
A simple galaxy simulation
Summary
Chapter 13: Extended Objects
Rigid bodies
Basic concepts of rigid body modeling
Modeling rigid bodies
Rotational dynamics of rigid bodies
Simulating rigid body dynamics
Example: a simple wind turbine simulation
Example: Rolling down an inclined plane
Rigid body collisions and bouncing
Example: Simulating a single bouncing block
Example: Colliding blocks
Deformable bodies
Mass-spring systems
Rope simulation
Cloth simulation
Summary
Part IV: Building More Complex Simulations
Chapter 14: Numerical Integration Schemes
General principles
Statement of the problem
Characteristics of numerical schemes
Types of integration schemes
Modifying Forcer to allow for different integration schemes
Euler integration
Explicit Euler
Implicit Euler
Semi-implicit Euler
Comparing the explicit and semi-implicit Euler schemes
Why use Euler and why not?
Runge-Kutta integration
Second-order Runge-Kutta scheme (RK2)
Fourth-order Runge-Kutta scheme (RK4)
Stability and accuracy of RK2 and RK4 compared with Euler
Verlet integration
Position Verlet
Velocity Verlet
Testing the stability and accuracy of the Verlet schemes
Summary
Chapter 15: Other Technical Issues
Doing physics in 3D
3D versus 2D physics
3D math
Creating classes for 3D objects and motion
Creating 3D models
Example: A rotating cube
Integrating with 3D engines
Looking ahead to Stage3D
Building scale models
Scaling for realism
A simple example
Choosing units
Scaling factors and parameter values
Rescaling equations
Building accurate simulations
Using Number for calculations
Choosing an appropriate integration scheme
Using an appropriate timestep
Using accurate initial conditions
Dealing with boundaries carefully
Summary
Chapter 16: Simulation Projects
Build a submarine
Brief review of the physics
The visual setup
The setup code
The basic motion code
Adding controls and visual effects
The full mover code
Further ideas
Build a flight simulator
Physics and control mechanisms of aircraft
What we will create
Creating the visual setup
Coding up the physics
Implementing the controls
Displaying flight information
Test flying the simulator
Further things to do
Create an accurate solar system model
What we will create
The physics
Coding up an appropriate integration scheme
Building an idealized single-planet simulation
Choosing appropriate scaling factors
Obtaining planetary data and initial conditions
Basic solar system model
Incorporating accurate initial conditions
Comparing the model results with NASA data
Other things to do
Summary
Index
← Prev
Back
Next →
← Prev
Back
Next →