Presentation is loading. Please wait.

Presentation is loading. Please wait.

REFERENCES: Trigonometry and Applications.

Similar presentations


Presentation on theme: "REFERENCES: Trigonometry and Applications."— Presentation transcript:

1 REFERENCES: HTTP://EN.WIKIPEDIA.ORG/WIKI/TRIGONOMETRY Trigonometry and Applications

2 Outline 1. Vector motion (and an intro to vectors in general) 2. Rotation / angles in 2d. 3. Polar => Rectangular coordinates 4. Rectangular => Polar coordinates 5. A little physics (enough for lab8)

3 I. Motivation Our character movements so far: Other types of movement:

4 I. What is a (Rectangular 2d) vector? A collection of 2 values:  pos = [400, 300]  vel = [100, -30] # 100 px/s right, 30 px/s down A position (pos) An offset (vel) -30 100

5 I. Law of similar triangles -30 100 a b c α β γ T d e f α β γ U

6 I. Law of Similar Triangles, cont. -30 100

7 I. The "new" type of movement That's great, but we want asteroids-movement! The "new" type of vector motion:  Move n pixels (a distance) in this direction  Q: How do we represent a direction?  A: In 2d…an angle.  [In 3d: quaternion, euler angle, direction vector, … ]

8 II. Angles (2D) Two common systems: Degrees Radians By convention, 0 (degrees / radians) is to the right. A measure of rotation: Negative is clockwise (by convention) Positive is counter-clockwise (by convention) Also a description of orientation: How much we've rotate from the 0 (right) position

9 II. Angles (2D) Degrees 0 90 180 270 45 135 360720 -90 -180

10 II. Angles (2D) degrees, cont. The number 360 is sort-of arbitrary  Evenly divisible by a lot of numbers (2, 4, 8, …)  Loosely based on #days/yr  Babylonians used a sexagesimal number system (60-based instead of our 10-based system) In the radians system, the number has a physical meaning…

11 II. Angles (2D) radians What is π?  Common answer: 3.14159…  But what does it represent??? Definition of π… Circumference = 6.283" Diameter = 2" Circumference = 1.57" Diameter = 0.5"

12 II. Angles (2D) radians, cont.

13 r d θ

14 0 π Let's say diam = 4 …the circumference would be 4π … halfway around would be 2 π (d) …the radius is 2 …So the radian angle would be 2 π / 2 … π d

15 II. Conversions

16 II. Conversions, cont. …Or just use the math functions.  math.radians(num)  Converts num (assumed to be in degrees) to radians  math.degrees(num)  Converts num (assumed to be in radians) to degrees Caution:  If you see the number 45.0 in your code, is it in radians or degrees?  You can't tell – neither can python.  Comments are very important!

17 II. Complementary Angles A pair of complementary angles add up to 180 (degrees) If Θ and Φ are complementary… Θ + Φ = 180 The complement of 34 degrees is 146 degrees.

18 II. Back to the original problem Really – how do we move forward n pixels at an angle θ ?!? CartesianCoordinates Angle (degrees)offset in xoffset in y 0n0 900n 180-n0 2700-n 45?? 15.4??

19 III. Trig to the rescue! θ A O H

20 III. Trig functions θ A O H H is the distance we want to move forward A is the amount to add to our x-position O is the amount to add to our y-position (note pygame's y axis) (A,O) is the Cartesian equivalent of (H, θ) in polar coordinate. A=H*cos( θ) O=H*sin( θ)

21 III. Polar => Cartesian conversion CartesianCoordinates Angle (degrees)offset in xoffset in y 010 9001 1800 2700 15.4 Back to our original problem… Initial assumption: distance is n (e.g. 15) This is the hypotenuse's length The length of the adjacent side's length (which we don't know)… …but we can calculate A = H * cos(angle) = n * cos(15.4) = 14.46 n=15 ?? 14.46 The opposite side's length this time O = H * sin(angle) = n * sin(15.4) = 3.984 3.984 15.4 ⁰

22 III. Vectors

23 III. Quadrants and Sign of trig functions Let θ be any angle in the range –infininty…+infinity. θ will be in one of 4 quadrants. The following trig functions are positive in each quadrant:  Q1: Sin( θ ), Cos( θ ), Tan( θ )  Q2: Sin( θ )  Q3: Tan( θ )  Q4: Cos( θ ) Menmonic: "All Students Take Calculus" Quadrant IQuadrant II Quadrant III Quadrant IV

24 III. “Negative Distances” Let's say our angle β is 130 degrees (Quadrant II) Problem: We can't draw a right triangle with an (obtuse) angle β We can, however, compute a complementary angle, α  And then a right-triangle using that angle. Notice how the adjacent side (if hyptonuse is 1) is cos(50) ≈ 0.64 This is the correct horizontal offset, but it is to the left of the origin.  So…it really should be -0.64. Your calculator, pygame.math, etc, already handle this. cos(130) ≈ -0.64 Interpret this as a distance of 0.64, but to the left of the origin. β 0.64 α

25 III. Example [Moving object, firing projectiles]  [Add a "rotate-able" object]

26 IV. Rectangular => Polar Why?  Given: face-pos (fx, fy) and candy position (cx, cy)  Find: angle to point the hand (towards candy)  Estimate for this scenario: ~25 degrees [fx, fy] [cx, cy]

27 IV. Rectangular to Polar We need to find:  n: hypotenuse  θ: the angle of the hand (at fx, fy) Steps:  [on board] Inverse Trig Functions:  if sin(ψ) = a, sin -1 (a) = ψ  Similar for cos and tan.  [continue solving on board]  problems with just inverse trig functions  Solution: math.atan2(opp, adj) [fx, fy] [cx, cy]

28 IV. Minimal amount of physics for the lab


Download ppt "REFERENCES: Trigonometry and Applications."

Similar presentations


Ads by Google