Fundamentals of Computer Graphics Note 2 - Miscellaneous Math
Sets and Mappings
Common sets of interest include
• R—the real numbers;
• R+—the nonnegative real numbers (includes zero);
• R2—the ordered pairs in the real 2D plane;
• Rn—the points in n-dimensional Cartesian space;
• Z—the integers;
• S2—the set of 3D points (points in R3) on the unit sphere.
Logarithms
Trigonometry
Shifting identities:
Pythagorean identities:
Addition and subtraction identities:
Half-angle identities:
Product identities:
Arbitrary triangles with side:
Vectors
Identities:
Dot Product:
The dot product obeys the familiar associative and distributive properties we have in real arithmetic:
dot product:
Cross Product
Identities:
Assume:
So:
Property:
Cross product:
So, in coordinate form,
Orthonormal Bases and Coordinate Frames
Identities:
Global and Local Coordinate System:
Curves and Surfaces
2D Implicit Curves
An implicit equation in two dimensions:
f does have values for all (x, y). We can think of f as a terrain, with sea level at f = 0 . The shore is the implicit curve. The value of f is the altitude.
For example:
using vector:
The vector form of an equation often suggests more geometry and intuition than the equivalent full-blown Cartesian form with x and y.
It is usually advisable to use vector forms when possible.
The 2D Gradient
If we think of the function f(x, y) as a height field with height = f(x, y), the gradient vector points in the direction of maximum upslope, i.e., straight uphill. The gradient vector ∇f(x, y) is given by
Implicit 2D Lines
We can start with any (A, B) perpendicular to (x1-x0, y1-y0).
Such a vector is just (A, B) = (y0 - y1, x1 - x0) by the same reasoning.
This means that the equation of the line through (x0, y0) and (x1, y1) .
The full equation for the line:
Unit vector:
The distance from a point to the line is the length of the vector k(A, B), which is
For the point (x, y) + k(A, B), the value of f(x, y) = Ax + By + C is
We can see that the signed distance from line Ax + By + C = 0 to a point (a, b) is
Implicit Quadric Curves
Two-dimensional quadric curves
Examples of quadric curves include the circle with center (xc, yc) and radius r,
and axis-aligned ellipses of the form
where (xc, yc) is the center of the ellipse, and a and b are the minor and major semi-axes.
Surface Normal to an Implicit Surface
A surface normal (which is needed for lighting computations, among other things) is a vector perpendicular to the surface.
The surface normal at a point p on an implicit surface is given by the gradient of the implicit function
the surface -f§ = 0 is the same as surface f§ = 0 but has directionally reversed gradients, i.e.,
-∇f§ = ∇(-f§).
Implicit Planes
As an example, consider the infinite plane through point a with surface normal n. The implicit equation to describe this plane is given by
Sometimes we want the implicit equation for a plane through points a, b, and c.
This allows us to write the implicit plane equation:
determinant:
Linear Interpolation
Two points a and b are associated with a parameter t to form the line
The parameter t is just the fractional distance between xi and xi+1:
Notice that Equation has this form with
Triangles
2D Triangles
Triangles Area:
Barycentric coordinates:
As a nonorthogonal coordinate system, where the coordinate origin is a and the vectors from a to b and c are the basis vectors. any point p can be written as:
Note that we can reorder the terms in Equation to get
Often people define a new variable α to improve the symmetry of the equations:
which yields the equation
with the constraint that
Barycentric coordinates are defined for all points on the plane. A particularly nice feature of barycentric coordinates is that a point p is inside the triangle formed by a, b, and c if and only if
- If one of the coordinates is zero and the other two are between zero and one, then you are on an edge. If two of the coordinates are zero, then the other is one, and you are at a vertex.
- barycentric coordinates is that Equation in effect mixes the coordinates of the three vertices in a smooth way.
Given a point p, how do we compute its barycentric coordinates?
- Linear system
- Implicit lines
- Areas
3D Triangles
One wonderful thing about barycentric coordinates is that they extend almost transparently to 3D
The normal vector(right-hand rule)
The area
Recall that
get