Linux

Chromium, Cobalt, and Argon (room 242) are Linux systems.

The Linux PCs in room 265 are also available.

CIT Intro to Unix: http://wings.buffalo.edu/computing/Documentation/unix/unix.html

    setenv PYTHONPATH /home/dms/depape/python
to get working version of PyOpenGL
Put it in your ~/.cshrc file to have it done automatically




Math







Distances

Distance between two points (x0,y0) and (x1,y1):

dist = math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))

Distance between two 3D points (x0,y0,z0) and (x1,y1,z1):

dist = math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) + (z1-z0)*(z1-z0))

Note: sqrt is considered an expensive (i.e. slow) function






Bounds

Simple representation of approximate area covered by an object

Always completely contains the object

Typically a box or a circle/sphere




Bounding Box

To compute a bounding box of an object, assuming its vertices are contained in the list obj.vertices:

minX = obj.vertices[0][0]
maxX = obj.vertices[0][0]
minY = obj.vertices[0][1]
maxY = obj.vertices[0][1]

for v in obj.vertices:

    if minX > v[0]:
        minX = v[0]
    elif maxX < v[0]:
        maxX = v[0]

    if minY > v[1]:
        minY = v[1]
    elif maxY < v[1]:
        maxY = v[1]





Bounding Box

To determine if a point (x,y) is inside a bounding box:

    (x >= minX) and (x <= maxX) and (y >= minY) and (y <= maxY)





Bounding Sphere

To compute a bounding sphere, find a center, and then the most distant vertex:

xsum,ysum = 0,0
for v in obj.vertices:
    xsum += v[0]
    ysum += v[1]
center = [ xsum / len(obj.vertices) , ysum / len(obj.vertices) ]

radius = 0
for v in obj.vertices:
    d = distance(v, center)
    if d > radius:
        radius = d





Bounding Sphere

To determine if a point (x,y) is inside a bounding sphere:

    distance(center, (x,y)) <= radius





Trigonometry

sin(A) = opposite / hypotenuse
cos(A) = adjacent / hypotenuse
tan(A) = opposite / adjacent

or

opposite = hypotenuse * sin(A)
adjacent = hypotenuse * cos(a)

or

x = distance * cos(A)
y = distance * sin(A)





Trigonometry






Radians

Standard math library functions use radians

360 degrees = 1 full circle = 2 π radians

(Circumference of unit circle = 2 π)


    radians = degrees / 360.0 * 2 * math.pi

or

    radians = degrees / 180.0 * math.pi





Making a Circle

    glBegin(GL_LINE_LOOP)
    for degrees in range(0, 360): 
        radians = degrees / 180.0 * math.pi
        x = math.cos(radians) * radius
        y = math.sin(radians) * radius
        glVertex2f(x,y)
    glEnd()





Driving

Vehicle has direction and speed of travel

Direction is orientation - rotation about Z

To move forward:

    distance = speed * time

    dx = math.cos(direction) * distance
    dy = math.sin(direction) * distance

    x = x + dx
    y = y + dy





atan2

atan2 converts from (X,Y) coordinates back to angles

Note: it takes arguments in the order Y, X

 
    angle = math.atan2(y,x) * 180.0 / math.pi





Interpolation

Deriving a value for something from two pre-defined values (extremes)

e.g. Moving object from one position to another, over time






Linear Interpolation

Interpolation expressed as fractional distance between the two extremes

Ranges from 0.0 to 1.0
0.0 = first point; 1.0 = second point






Linear Interpolation

For a single value, with extremes V0 & V1 and interpolation fraction A:

    V = (1 - A) * V0 + A * V1


For multiple values, such as XYZ position, use the same fraction A for all:

    X = (1 - A) * X0 + A * X1
    Y = (1 - A) * Y0 + A * Y1
    Z = (1 - A) * Z0 + A * Z1





Timing

Linear Slow-in Slow-out
X = tX = -2*t*t*t + 3*t*t





Randomness

We often would like the behavior of a program to change or be unpredictable - to not be exactly the same every time we run it.

In other cases, randomness helps eliminate unwanted artifacts, such as obvious, excessively regular or repeated patterns. These include patterns in the appearance and in the movement of objects.






Randomness

Things that can be randomized include:






Random Number Functions

Randomness is added to programs by using random numbers. These are generated by random number functions.

Python has a package called random.
Two of the functions it provides are:






Random Number Functions

In C, the standard random number functions are: