Plan
- Review barn modification code from last time. Did people try some
errors? We'll look at one error in the Barn code together.
- color primaries
- Additive vs Subtractive
- color models
- Look at the Fireworks color pickers
- Specifying colors in OpenGL and in TW
- New OpenGL and TW stuff in demos (and where to find the demos).
Oh, note that it's only necessary to import TW; the other packages are
included with TW.
- Some stuff from TW and GL, all exhibited in ColorCone.
- twBoundingBox
- twKeyCallback
- glutPostRedisplay
- twHSV2RGB: hue angle is in degrees from 0=red
- cos/sin: note that the argument is in radians
- creating and using objects in Python.
- Exercise: Modify barn so that there is shading across a region, say
across the roof, maybe dark brown at the ridge and light brown at the
eave, or whatever choice you like.
- parametric equations
- lines
- triangles
- quads (but these are not used by OpenGL, which triangulates)
- parametric equations as weighted sums (weighted averages)
- We'll look at the code for some of the functions
of TW's geometry functions. In
particular, we'll play with twPointOnLine and twWeightedAverage.
Line Representation and Interpolation
Line Representations
Suppose we have two points: A = (1,5) and B = (6,15). How can we
represent the line through those points?
- Implicit: Ax+By+C=0
- Explicit: y=mx+b
- Parametric: x(t)=ax+b; y(t)=...
Now, in 3D. Two points are A = (1,2,3) and B = (6,9,4).
- x(t) = ..., where x(0) = Ax = 1 and x(1) = Bx = 6
- y(t) = ...
- z(t) = ...
- P(t) = ...
Let's think of the same line as P(t) = P0 + V*t. What is that
formula?
Let's look at the code in TW.py for the following functions:
- twVector
- twVectorScale
- twPoint
- twPointOnLine
- twWeightedAverage
Let's play with these functions some
- find the vector between the endpoints
- given the vector, find the missing endpoint
- Find the midpoint of the line.
- Find the following points:
- t=0
- t=1
- t=0.5
- t=0.1
- t=0.9
- t=2
- t=-3
- Express these points as weighted averages
Suppose the color of A is cyan, and the color of B is yellow.
- What is the color of t=0, t=1, t=0.5, t=0.1, t=0.9, t=2, t=-3
Implement a program to draw lines like this. Start with ColorCube,
rip out the stuff you don't need, and just draw a thick line. Check
the bounding box to make sure it's okay.
Triangles
In reality, interpolation in OpenGL is done using scan lines of
rasterized triangles.
For a demo,
see color/ColorTriangle.py
Imagine computing the colors of the endpoints of a horizontal scan
line. Imagine interpolating the colors as you move across.
Quads
The math of interpolating in Quads is just a 2D generalization of
interpolating on lines:
- define two dimensions: s and t
- interpolate in the s dimension to find two endpoints
- interpolate in the t dimension between these two points to find
the desired point.
- or, switch the roles of s and t
Let's do an example. Counterclockwise from lower left:
A = (0,0,0)
B = (1,2,3)
C = (3,5,4)
D = (2,3,1)
Questions:
- Is this quad flat? How could we tell?
- What are the coordinates of the point P=(0.1,0.2) in (s,t) parameter space? Try this both ways. Use the TW functions twWeightedAverage and/or twPointOnLine.
- If the colors of the vertices are RYBG, what is the color of P?
Line Intersections
Suppose we have two pairs of points, such as the corners of the quad above:
A = (0,0,0)
B = (1,2,3)
C = (3,5,4)
D = (2,3,1)
Can we find the intersection point of lines AC and BD? How?
- Determine two parametric equations. Use different parameters! Call
them the s line and the t line.
- Set the equations equal, since point of intersection will
satisfy both lines.
- Solve for the parameters of the intersection point
- Analyze the parameters of the intersection point: do
the segments intersect?
- Evaluate to find the point of intersection.
Written by Scott D. Anderson
scott.anderson@acm.org

This work is licensed under a Creative Commons
License.