Trigonometry and Applications REFERENCES HTTP EN WIKIPEDIA ORGWIKITRIGONOMETRY

  • Slides: 28
Download presentation
Trigonometry and Applications REFERENCES: • HTTP: //EN. WIKIPEDIA. ORG/WIKI/TRIGONOMETRY

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

Outline 1. 2. 3. 4. 5. Vector motion (and an intro to vectors in

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

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

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

I. What is a (Rectangular 2 d) vector? �A collection of 2 values: pos

I. What is a (Rectangular 2 d) 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) 100 -30

I. Law of similar triangles � 100 -30 b α c γ a β

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

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

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

I. The "new" type of movement �That's great, but we want asteroids-movement! �The "new"

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 2 d…an angle. � [In 3 d: quaternion, euler angle, direction vector, … <later>]

II. Angles (2 D) Two common systems: • Degrees • Radians By convention, 0

II. Angles (2 D) 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

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

II. Angles (2 D) Degrees 90 45 135 -180 0 360 180 270 -90 720

II. Angles (2 D) degrees, cont. �The number 360 is sort-of arbitrary Evenly divisible

II. Angles (2 D) 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…

II. Angles (2 D) radians �What is π? Common answer: 3. 14159… But what

II. Angles (2 D) 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"

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

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

II. Angles (2 D) radians, cont. � d r θ

II. Angles (2 D) radians, cont. � d r θ

II. Angles (2 D) radians, cont. d π Let's say diam = 4 …the

II. Angles (2 D) radians, cont. d π 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 …π 0

II. Conversions �

II. Conversions �

II. Conversions, cont. �…Or just use the math functions. math. radians(num) � Converts num

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!

II. Complementary Angles �A pair of complementary angles add up to 180 (degrees) If

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.

II. Back to the original problem �Really – how do we move forward n

II. Back to the original problem �Really – how do we move forward n pixels at an angle θ ? !? Cartesian Coordinates Angle (degrees) offset in x offset in y 0 n 0 90 0 n 180 -n 0 270 0 -n 45 ? ? 15. 4 ? ?

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

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

III. Trig functions � H O θ A A=H*cos(θ) H is the distance we

III. Trig functions � H O θ A A=H*cos(θ) H is the distance we want to move forward A is the amount to add to our x-position O=H*sin(θ) 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.

III. Polar => Cartesian conversion Back to our original problem… Initial assumption: distance is

III. Polar => Cartesian conversion Back to our original problem… Initial assumption: distance is n (e. g. 15) This is the hypotenuse's length Cartesian Coordinates Angle (degrees) offset in x offset in y 0 1 0 90 0 1 180 -1 0 270 0 -1 15. 4 14. 46 n=15 3. 984 ? ? 15. 4⁰ ? ? 14. 46 3. 984 The length of the adjacent side's length (which we don't know)… …but we can calculate The opposite side's length this time A = H * cos(angle) O = H * sin(angle) = n * cos(15. 4) = n * sin(15. 4) = 14. 46 = 3. 984

III. Vectors �

III. Vectors �

III. Quadrants and Sign of trig functions �Let θ be any angle in the

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: Q 1: Sin(θ), Cos(θ), Tan(θ) Q 2: Sin(θ) Q 3: Tan(θ) Q 4: Cos(θ) Quadrant III �Menmonic: "All Students Take Calculus" Quadrant IV

III. “Negative Distances” � Let's say our angle β is 130 degrees (Quadrant II)

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

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

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

IV. Rectangular => Polar �Why? Given: face-pos (fx, fy) and candy position (cx, cy)

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 [cx, cy] [fx, fy]

IV. Rectangular to Polar �We need to find: n: hypotenuse θ: the angle of

IV. Rectangular to Polar �We need to find: n: hypotenuse θ: the angle of the hand (at fx, fy) �Steps: [on board] [fx, fy] �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. atan 2(opp, adj) [cx, cy]

IV. Minimal amount of physics for the lab �

IV. Minimal amount of physics for the lab �