Lagrange Multipliers and the Calculus of Variation in Game Design
LAGRANGE MULTIPLIERS AND THE CALCULUS OF VARIATION IN GAME DESIGN
PAUL BOUTHELLIER DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE UNIVERSITY OF PITTSBURGH-TITUSVILLE TITUSVILLE, PA 16354 [email protected] FINDING THE QUICKEST PATH INITIAL PROBLEM
• Can travel at a speed of si on level li • Find the path C which minimizies the time it takes to get from (0, 0) to (1000, 1000)
• Consider general speeds • Consider falling under gravity alone • Falling under gravity with an atmosphere • Dealing with obstacles • R2, R3, R4 TECHNIQUES
• Lagrange Multipliers
• Euler-Lagrange Equation
• Beltrami Equation
• Numerical Analysis THE LAGRANGE MULTIPLIER METHOD The Lagrange Multiplier Method
+ 1, 2, … , = 𝑛𝑛 2 2 𝑑𝑑𝑑𝑑 𝑙𝑙𝑙𝑙 𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀 𝑓𝑓 𝑑𝑑 𝑑𝑑 𝑑𝑑𝑑𝑑 � 𝑖𝑖=1 𝑠𝑠𝑠𝑠 THE LAGRANGE MULTIPLIER METHOD The Lagrange Multiplier Method
+ 1, 2, … , = 𝑛𝑛 2 2 𝑑𝑑𝑑𝑑 𝑙𝑙𝑙𝑙 𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀𝑀 𝑓𝑓 𝑑𝑑 𝑑𝑑 𝑑𝑑𝑑𝑑 � 𝑖𝑖=1 𝑠𝑠𝑠𝑠 + 1, 2, … , = 𝑛𝑛 2 2 𝑑𝑑𝑑𝑑 𝑙𝑙𝑙𝑙 𝑓𝑓 𝑑𝑑 𝑑𝑑 𝑑𝑑𝑑𝑑 � 𝑖𝑖=1 𝑠𝑠𝑠𝑠 Lagrange Multipliers: Solving for the di d 1 is 9.717592076941 d 2 is 19.716469280426 d 3 is 30.320551487255 d 4 is 41.955199508211 d 5 is 55.250555011642 d 6 is 71.258726625095 d 7 is 91.996416566653 d 8 is 122.145576401652 d 9 is 176.855999289317 d 10 is 380.782915477145
Total time is 35.777931135649
Total distance is 1542.980226242951 EXAMPLE II
d 1 is 19.008231985751 d 2 is 40.261059108635 d 3 is 67.630647087404 d 4 is 112.345176987363 d 5 is 260.754884222299 d 6 is 260.754884222299 d 7 is 112.345176987363 d 8 is 67.630647087404 d 9 is 40.261059108635 d 10 is 19.008231985751
Total time is 57.877432196461
Total distance is 1519.980402465238 FIRST COUSIN: THE BRACHISTOCHRONE PROBLEM
Bernoulli (1696): Given two points A and B, find the path along which an object would slide (without friction) in the shortest time from A to B, if it starts at A in rest and is only accelerated by gravity. Solving The Brachistochrone Problem
Where y(x) is the solution which minimizes the time T
where
To make T stationary use the Euler-Lagrange equation However, as F does not contain x can use the special case-The Beltrami Identity
= 𝜕𝜕𝐹𝐹 𝐹𝐹 − 𝑦𝑦′ 𝐶𝐶 𝜕𝜕𝑦𝑦′ Solving Beltrami's Identity Using separable equations, substitutions, and some hand-waving we get
x(t)=a(t-sin(t)) y(t)=a(1-cos(t))
Where the range t=0..tE comes from:
Time along curve Example
Letting xE=yE=1000 Brachistochrone: Lagrange Multiplier Method (n=1000 partitions) x(t)=572.917(t-sin(t)) d1=20.24 y(t)=572.917(1-cos(t)) d2=58.93 d3=111.74 t=0..2.412 d4=178.08 d5=258.56 d6=354.75 d7=469.44 d8=607.44 d9=777.67 d10=1000 Atmospheric Model of a Skydiver
m=mass of the skydiver g=gravity d=density of the air A=cross-sectional area
CD=coefficient of drag v=skydiver's velocity
= tanh(t ) 2𝑚𝑚𝑚𝑚 𝑔𝑔𝑔𝑔𝐶𝐶𝐷𝐷𝐴𝐴 𝑣𝑣 𝑡𝑡 𝑑𝑑𝑑𝑑𝐶𝐶𝐷𝐷 2𝑚𝑚 Graph of v(t)
Speed in mph
Approximate by: Example-Dealing with Terminal Velocity
Break the Problem Into Two Pieces
Minimum travel time is: 31.889174788418