1 / 11

Lesson 2

Lesson 2. By us. Movement. moving left/right/up/down is easy so are rotations but if the goal is to move diagonally, there is a problem the solution is trigonometry. The Right Triangle. every triangle has 3 sides the sum of internal angles is 180 degrees a 2 + b 2 = c 2. c. b. a.

conan
Download Presentation

Lesson 2

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. Lesson 2 By us

  2. Movement • moving left/right/up/down is easy • so are rotations • but if the goal is to move diagonally, there is a problem • the solution is trigonometry

  3. The Right Triangle • every triangle has 3 sides • the sum of internal angles is 180 degrees • a2 + b2 = c2 c b a

  4. Trig • let ‘x’ be an angle • sin(x) = opposite / hypotenuse • cos(x) = adjacent / hypotenuse • tan(x) = opposite / adjacent • you will never use “tan” in programming • “sin” and “cos” are crucial

  5. Trig 2 • sin(z) = opposite / hypotenuse • cos(z) = adjacent / hypotenuse • tan(z) = opposite / adjacent

  6. Trig 3 the scenario: • you have the angle (this._rotation) • you have the hypotenuse (speed) • now you need vertical length and horizontal length

  7. Trig 4 Math.sin (z) = y / velocity  y = Math.sin (z) * velocity Math.cos (z) = x / velocity  x = Math.cos (z) * velocity

  8. Trig 5 • so now that you have ‘x’ (horizontal displacement) • you also have ‘y’ (vertical displacement) ie: this._x += Math.cos (z) * velocity; this._y -= Math.sin (z) * velocity;

  9. WAIT A MINUTE • the input for Math.sin () or Math.cos () is in radians • 1 radian = PI / 180 degrees • 1 degree = 180 / PI radians • to get PI, you type: Math.PI

  10. More Radians example: z = z*Math.PI/180; //or z *= Math.PI/180; this._x += Math.cos (z) * velocity; this._y -= Math.sin (z) * velocity;

  11. DONE FOR TODAY!

More Related