Skip to content

Instantly share code, notes, and snippets.

Created August 12, 2016 16:51
SSCI
import math
class Point(object):
"""
Define a 3D point (x0, y0, z0) in space.
"""
def __init__(self,coordinates):
self.x = coordinates[0]
self.y = coordinates[1]
self.z = coordinates[2]
class Vector(object):
"""
Define a 3D vector <a, b, c> in space.
"""
def __init__(self, direction):
self.a = direction[0]
self.b = direction[1]
self.c = direction[2]
class Plane(object):
"""
Define a plane in 3D space by giving a point and a normal direction vector.
"""
def __init__(self, planepoint, normal_vector):
"""
planepoint is a Point object.
normal_vec is a Vector object.
"""
self.a = normal_vector.a
self.b = normal_vector.b
self.c = normal_vector.c
self.x = planepoint.x
self.y = planepoint.y
self.z = planepoint.z
self.d = self.a * self.x + self.b * self.y + self.c * self.z
def distance_to_point(self,target):
"""
Returns the shortest distance from a target poinpt (Point object) to a plane (Plane object).
Formula:
abs( a x1 + b y1 + c z1 + d )
D = --------------------------------
sqrt( a^2 + b^2 + c^2 )
"""
numerator = math.fabs( self.a * target.x + self.b * target.y + self.c * target.z + self.d )
denominator = math.sqrt( self.a**2 + self.b**2 + self.c**2 )
d = numerator/denominator
return d
if __name__=="__main__":
"""
This is the main driver.
Start here!
"""
P0 = Point( [1, 2, 3] )
V0 = Vector( [4, 5, 6] )
N0 = Plane( P0, V0 )
P1 = Point( [10, 12, 8] )
d = N0.distance_to_point(P1)
print d

South Seattle College Interview Computer Science Lecture August 10

Objects:

  • Primitive types and where we came from
  • Higher level languages and abstraction
  • Example code: vector calculus... points/vectors/planes
    • Example code
    • Look at the code: why abstraction
    • Walk through code, what happens here
  • Worksheet: expand on it
    • generalize to N-dimensional operation, what additional info do you need?
    • What is similar? what is different?

More details:

  • (No code)
  • start with very early programming: how did things look?
  • way back to the early days of programming: Cobol, Basic, Fortran - everything was numbers and function calls
  • operations on numbers, addresses of numbers
  • used to be, you had to understand computers at a circuitry level to program them
  • what's happened over the last 3 decades, is we're moved up to higher level
  • concept called "abstraction" - details of how things work are hidden away, don't have to deal with it
  • today, we're going to talk about how you do that in code

Objects

  • objects are the way you implement abstraction in code - the way you hide away details
  • it's a simple concept: an object is a collection of related data.
  • AN OBJECT IS A COLLECTION OF RELATED DATA.
  • That's it. But it's a very powerful idea.

Example:

  • Since this idea of "abstraction" is, by definition, abstract, it's important to have a concrete example
  • Let's start with this classes.py
  • Start where it says to start: at the main function
  • Very first line: we create a point.
  • Dealing with primitive types, but now let's see how we introduce a class
  • We have created a 3 dimensional point, and if we go back and review our vector calc, that point is defined by 3 distinct numbers
  • Here we are defining a type of object, called a point - a collection of data, x, y, and z, have a general template so we can define multiple instances of this object
  • And the point goes and stores those numbers in some particular way, we don't have to worry about it right now
  • Here we have another object, a vector, which similarly stores a set of related numbers
  • We have a plane object, which is defined by a set of related objects - a point and a vector
  • Objects store related data - not just primitive data, data can also be other objects

Activity Question 1: what is this code doing?

  • Form small group and discuss: what is this code doing?
  • pretty clear, at a high level, that this code is finding shortest distance from point to plane
  • objects: encapsulation: abstraction: this is what it looks like

Activity Question 2: extending the idea

  • Right now, code was written for 3D vectors
  • How would we change this to work for N-dimensional vectors?

Schedule/Outline:

	5 				5				5

| --------------------- | ------------------------- | ------------------ |

Objects, objects vs functions Vectors, vector ops, vector objects, brief review Activity/worksheet: * implementing solution to linear systems * what kind of objects would you need * what kind of data would store * what numbers we associate, primitive types * could do something more fun, like Netflix movie rating system * or do BOTH

Objects:

  • contrast with functions
  • primitive types
  • representing data with numbers
  • functions --> detail
  • objects --> abstractions, higher level
  • tie objects into computers/electronics generally

Objects:

  • example
  • vectors
  • 2D
  • 3D
  • N-dimensional vector
  • generalization - it doesn't matter how many dimensions

Objects:

  • activity worksheet
  • walk through instructions
  • end lecture at worksheet

South Seattle College Interview Engineering Dynamics Lecture August 10

  • Today, talking about rolling friction
  • Motivate this by starting with a real world example of this, talk through it
  • Watch a video, little bit of background

Video: http://tinyurl.com/ssci-train1 and http://tinyurl.com/ssci-train2

  • Big picture: what's going on here? railroad car needs more "bite," more friction
  • Engineering approach: think about force balance, F=ma
  • What forces are acting on this train? gravity force, normal force, forward force; we can also think about the detailed forces but let's abstract away the details: everything boils down to/contributes to one of those three forces
  • Contrast this with behavior of offroad hill climbing trucks

Video: http://tinyurl.com/ssci-dirt1

  • What's different? environment, surface area, traction, power delivery, center of gravity, incline, lots different
  • What's the same? the force diagram! still boils down to those same three forces: gravity force, normal force, forward force

Let's go through the handout together Question 1: tie together the math and the scenario

Exercise/handout:

  • Handout, math, equation, relationship
  • Quantitative relationship, what's similar, what's different
  • Tie in the verbal discussion (letting the real world be the authority) with the mathematical model

Big take-home conclusion of the lecture:

  • Where are the details? they've been abstracted away, lumped into one parameter
  • Why? nice and easy and simple
  • Algebraic model, no calculus, no material properties, no detailed information
  • Can go a long way with this kind of model

Outline:

Rolling friction:

  • train stuck on tracks spinning its wheel
  • bite/grip: engineering term is friction
  • when train is sitting still: static analysis, do a force balance:
    • F = ma
    • force diagram, static versus with wheels, similarities
    • What forces are acting on the train? train has gravity force, opp. and equal normal force
    • now contrast that behavior with a sand buggy racing up a sandy hill (inclined):
    • what's different? a lot
    • what's the same? force diagram analysis
    • we're not going to worry about the details of what's different, let's focus on what's the same
    • Engineering: lumped parameter models
  • handout: math, equations, relationships, data table - and asking them, where are the details?
  • Exercise: fuel efficiency, back of envelope, engineering models, weight --> gravity force --> friction force --> distance --> work --> heat value --> amount of fuel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment