1 / 11

Code examples

Code examples. Mechanics: random balls Biology/evolution: flocking Game of tag. Intro to bodies interactions. The attraction between two bodies is given by F= g*m 1 *m 2 /r 2

alexa
Download Presentation

Code examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Code examples • Mechanics: random balls • Biology/evolution: flocking • Game of tag

  2. Intro to bodies interactions • The attraction between two bodies is given by F= g*m1*m2/r2 • Where F is force, g is the gravitational “constant” [aka fudge factor], m’s are masses for bodies one and two and r is the distance between them.

  3. r the distance between two bodies Point 2 • Using the Pythagorean theorem we can find the distance between two points hypotenuse = r y x Point 1 a2 + b2 = c2 Hence, x2 + y2 = r2

  4. Trigonometry review y • cos = x • sin  = y • tan  = y/x • atan y/x =   x

  5. mmm vectors…. y Mass 2 ‘out there’ • We need to separate the x and y directions of the force. •  is the angle • So F, the force arrow has an x and y part. • Fx = (cos ) * F • Fy = (sin ) * F F  x Mass 1 at ‘center’

  6. Put it all together Lets ignore m2 [its very very very small], then F= g*m1*m2/r2, becomes F = g*m/r2 But, r2 = x2 + y2, so F = g*m/(x2 + y2) But, Fx = (cos )*F, so Fx = (cos )*g*m/(x2 + y2) Similarly, Fy = (sin )*g*m/(x2 + y2)

  7. How does the computer know what's what? y • x is x and y is y • But the computer does not know what  is. • atan y/x =   x

  8. Using atan y/x =  Remember, Fx = (cos )*g*m/(x2 + y2) And, Fy = (sin )*g*m/(x2 + y2) So, Fx = (cos [atan y/x])*g*m/(x2 + y2) And, Fy = (sin [atan y/x])*g*m/(x2 + y2)

  9. What does force do? • If you hit a tether ball then you are the force and the ball then has a velocity as it flies through the air. • Hence we need velocity terms for our bodies: V • Vx = Vx + Fx • Vy = Vy + Fy • The velocity gets added to it self just like with a tether ball: the new velocity adds its old velocity to the new force of hitting it again.

  10. Next step translate into code

More Related