1. MORE TRIG (AND BASIC VECTORS) 2. INHERITANCE (CHAPTER 9) Lecture 10 (Last one!)

Slides:



Advertisements
Similar presentations
Vectors and Two-Dimensional Motion
Advertisements

Python Objects and Classes
Graphing Ordered Pairs
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1-1 Angles 1.1 Basic Terminology ▪ Degree Measure ▪ Standard Position ▪ Coterminal Angles.
Using Polar Coordinates Graphing and converting polar and rectangular coordinates.
Chapter 1. Vectors and Coordinate Systems
The Unit Circle.
What Is A Radian? 1 radian = the arc length of the radius of the circle.
REFERENCES: Trigonometry and Applications.
Converting Between Rectangular and Polar Coordinates Sometimes we want to change from rectangular coordinates to polar coordinates, and from polar coordinates.
A Physicists’ Introduction to Tensors
Vectors Sections 6.6.
Displacement and Velocity Chapter 2 Section 1. Displacement Definitions Displacement – The change in position of an object from one point to another in.
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
Starter If the height is 10m and the angle is 30 degrees,
Vector addition, subtraction Fundamentals of 2-D vector addition, subtraction.
Trigonometry Overview Part 2 tom.h.wilson Department of Geology and Geography West Virginia University Morgantown, WV.
Objective: Find the components of a vector.. Number plane, or Cartesian coordinate system – a plane determined by the horizontal line called the x- axis.
Inheritance. Inhertance Inheritance is used to indicate that one class will get most or all of its features from a parent class. class Dog(Pet): Make.
Methods in Computational Linguistics II Queens College Lecture 7: Structuring Things.
Chapter 6 ADDITIONAL TOPICS IN TRIGONOMETRY. 6.1 Law of Sines Objectives –Use the Law of Sines to solve oblique triangles –Use the Law of Sines to solve,
Circular Motion Kinematics 8.01 W04D1. Today’s Reading Assignment: W04D1 Young and Freedman: 3.4; Supplementary Notes: Circular Motion Kinematics.
Locating Points on a Circle Sine Cosine Tangent. Coordinates Systems Review There are 3 types of coordinate systems which we will use: Absolute Incremental.
11/27/07. >>> Overview * objects * class * self * in-object methods * nice printing * privacy * property * static vs. dynamic * inheritance.
Object-oriented Programming (review + a few new tidbits) "Python Programming for the Absolute Beginner, 3 rd ed." Chapters 8 & 9 Python 3.2 reference.
General physics I, lec 2 By: T.A.Eleyan 1 Lecture 2 Coordinate Systems & Vectors.
Chapter 3 Vectors and Two-Dimensional Motion. Vector vs. Scalar A vector quantity has both magnitude (size) and direction A scalar is completely specified.
Chapter 3 Vectors. Coordinate Systems Used to describe the position of a point in space Coordinate system consists of a fixed reference point called the.
Unit 3 Vectors and Motion in Two Dimensions. What is a vector A vector is a graphical representation of a mathematical concept Every vector has 2 specific.
Chapter 3 Vectors. Coordinate Systems Used to describe the position of a point in space Coordinate system consists of a fixed reference point called the.
Starter If you are in a large field, what two pieces of information are required for you to locate an object in that field?
Scalar Quantities Scalar quantities are measurements that have only magnitude (size) but no direction. Examples of scalar quantities are; Distance Speed.
A)2D Vector Conversion and Addition b)Vectors on your Calculator c)Vector addition practice d)3D Spherical to Cartesian ENGR 34 Chapter 2, Day 1 2D & 3D.
CGDD 4003 THE MATH LECTURE (BOILED DOWN, YET LIGHTLY SALTED)
Classes & Inheritance Review
Vectors. Adding Vectors += Resultant Adding Vectors += Resultant +=
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.
Forces in Two Dimensions
Object Oriented Programing (OOP)
Classes COMPSCI 105 SS 2015 Principles of Computer Science.
6.3 Vectors in a Plane (part 3) I. Using Angled Vectors (put calculator in degree mode). A) The vector must be in Component form (standard position) B)
Radian Angle Measures 1 radian = the angle needed for 1 radius of arc length on the circle still measures the amount of rotation from the initial side.
A Mathematics Review Unit 1 Presentation 2. Why Review?  Mathematics are a very important part of Physics  Graphing, Trigonometry, and Algebraic concepts.
VECTORS. BIG IDEA: Horizontal and vertical motions of an object are independent of one another.
Section 4.1. Radian and Degree Measure The angles in Quadrant I are between 0 and 90 degrees. The angles in Quadrant II are between 90 and 180 degrees.
Trigonometric Functions. Cosecant is reciprocal of sine. Secant is reciprocal of cosine. Cotangent is reciprocal of tangent.
Trigonometry and Applications References: xyz. Motivation Our character movements so far: Other types of movement:
8-6 Vectors in a Plane Greg Kelly, Hanford High School, Richland, Washington This is a Vector It appears as a line segment that connects two points It.
Trigonometry and Applications References: xyz. Review (?) from ETGG1801 Angles – As a measure of rotation and/or orientation – Radians & Degrees (and.
REFERENCES: Trigonometry and Applications.
Object-Oriented Programming (OOP) in Python References: Chapter 8.
Trigonometry and Applications References: xyz. Motivation Our character movements so far: Other types of movement:
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Section 1-9: Graphing Data on the Coordinate Plane
Object-Oriented Programming (OOP) in Python
Evaluating Inverse Trig Functions or.
Bearings and Navigation
Andy Wang Object Oriented Programming in C++ COP 3330
Object Oriented Programming
Graphing Ordered Pairs
POLAR COORDINATES Point P is defined by : P    .
START UP DAY 62 Kirby hits a ball when it is 4 ft above the ground with an initial velocity of 120 ft/sec. The ball leaves the bat at a 30° angle with.
Kinematics Projectile Motion
The COORDINATE PLANE The COORDINATE PLANE is a plane that is divided into four regions (called quadrants) by a horizontal line called the x-axis and a.
Vectors.
POLAR CURVES Tangents.
Presentation transcript:

1. MORE TRIG (AND BASIC VECTORS) 2. INHERITANCE (CHAPTER 9) Lecture 10 (Last one!)

Part I: More Trig Recall:  Angles (orientation and rotation)  Polar vs. Cartesian Coordinates (and offsets)  Polar => Cartesian conversion for “asteroids-style” movement (vs. normal “pacman” style movement) What we still need  Cartesian => Polar conversion (and applications)  Generalize the idea of a vector (and look at a few properties)  Define acceleration and velocity and their applications.

Cartesian => Polar coordinates Motivation:  Control orientation with the mouse. Previously we knew H and θ; We wanted to calculate Δx and Δy  Δx is the amount to change our x-position.  Δy is the amount to change our y-position. Now, however, want to calculate θ (from Δx and Δy) X rotSurf = pygame.transform.rotate( origSurf, degrees)

Cartesian => Polar, cont. θ A O H X We know initially: The position of the plane (x, y) The position of the mouse (mx, my) We want to calculate: The angle θ First step: We can calculate A and O below using our givens: A = mx – x O = my - y Note: it does make a difference which order you do the sub. Think of both as directions negative = left. positive = right. Similar for O

Example Cartesian => Polar (here using arcsin)  Givens:  Plane at (50, 500)  Target at (200, 150)  Step1: Calculate offsets towards target  Note how we take destination minus source  Step2: Calculate hypotenuse length  Step3: Calculate theta = = -350 (50,500) (200,150)

Cartesian => Polar, Problem with asin ( and acos ) θ = = -350 (50,500) (200,150) φ (-100)-50 = = -350 (50,500) (-100,150) WRONG! ψ should be ≈ 113 degrees Asin ignores the sign of the horizontal direction. δ If we're in quadrant II or III, we need the complement of ψ (180 – ψ).

Cartesian=>Polar, problem with atan.

Cartesian => Polar

Conversions finished

Example [Making object point towards a point]

Part III. Inheritance Overview Basically,  basing a new (derived) class from an existing one (base).  You "inherit" all methods (and attributes) from the base class.  You then:  Add new methods  Replace existing methods Although you can still call the base class's version

Abstract example class Base(object): def __init__(self, x): self.num = x def foo(self, string): return string * self.num class Derived(Base): def bar(self): return self.num ** 2 def foo(self, string): # REPLACES "inherited" foo return string * self.bar() A = Derived(4) # Note, we're using Base's __init__ method. print(A.foo("ABC")) # Calling the replaced method print(A.bar()) # Call a new method. One problem: If we want to add new attributes to Derived…

Calling (hidden) base class methods. class A(object): def f(self): print("A.f") class B(A): def f(self): print("B.f") obj = B() obj.f() # Print's B.f B.f(obj) # Same as above It appears as if we've replaced A's version of f, but it's actually just hidden.

Calling (hidden) base class methods, cont. class A(object): def f(self): print("A.f") class B(A): def f(self): A.f(self) # Calls the "hidden" f. print("B.f") obj = B() obj.f() # Print's 'A.f' then 'B.f' When you call base class methods like this, it is the only time self isn't passed automatically.

Adding attributes to a new class class Base(object): def __init__(self, x): self.num = x def foo(self, string): return string * self.num class Derived(Base): def __init__(self, x, y): Base.__init__(self, x) self.num2 = y def bar(self): return self.num ** 2 + self.num2 ** 2 A = Derived(4, 6) # Calling the new __init__ method. print(A.foo("ABC")) # Calling the inherited method print(A.bar()) # Call a new method.

isinstance function Used to determine if an object is of a given type isinstance(5, int) # True isinstance("5", int) # False isinstance("5", str) # True class Foo(object): … x = Foo() isinstance(x, Foo) # True

isinstance and inheritance A derived class object is considered:  an instance of the derived class (no surprise)  an instance of the base class class A(object): … class B(A): … x = A() y = B() isinstance(x, A) # True isinstance(x, B) # False isinstance(y, B) # True isinstance(y, A) # True

Example [Make the spaceship into a base class and add enemies that fire on the player]