Given two points, P1 and P2 we can
express the vector they determine by
v = P2-P1
Lines
A line is specified by a point P and a vector v.
And can be expressed by a point P0 and a vector d.
P(α) = P0+αd
This is a parametric form of the equation.
α varies from 0 to 1 (to draw the line segment)
Dot product of two vectors.
if u and v are vectors. u·v is the dot product
u·v =
uxvx +
uyvy +
uzvz
u·v = |u||v| cos(Θ), where Θ is the angle between the two vectors.
|u|2 = u·u =
ux2+
uy2+
uz2
if u·v = 0, then cos(Θ)=0 and &Theta=nπ +π/2;
So the angle between two vectors can be calculated
cos(Θ) = u·v/|u||v|
The cross product of two vectors.
if u and v are vectors, u×v is the cross product.
u×v = <
uyvz - uzvy, uzvx - uxvz, uxvy - uyvx>
u×v = n|a||b|sin(Θ), where n is a unit vector orthognal to both u and v
We sometimes want to construct three mutually orthognal vectors in space, given two vectors in a plane
Given a, b, vectors in a planne.
u = a;
Compute w = a×b, a normal to both u and b.
Compute v = u×w, a normal to both u and w.
The three orthognal vectors are then u,v,w
Such a system can be either right handed or left handed
To tell the type of system, put your hand on the positive x axis, your thumb along the positive z axis, and curl your fingers towards the positive y axis.
The hand you use tells you the type of system.
Convex Hulls
Given a set of points, Q, a convex hull is the smallest
convex polygon which contains all of the points in Q either within the polygon or on the edges of the polygon.
Given a board, with nails at each point, a convex hull is created by snapping a rubber band around all of the nails.
This is an area known as computational geometry.
We are going to look at this because
It gives us an application for dot and cross products (in 2D)
It gives a graphical application to mess with
It is good fun!
There are a number of algorithms for finding a convex hull given
a set of points.
We will look at one called the Graham's Scan
Graham-Scan(Q)
Find p0, the point in Q with the minimum y coordinate,
in the case of a tie, select the point with the
minimal x coordinate.
This is a linear search through the points
We know that the plane is divided into a
half-plane along the line x=p0.x
Let p-1 be a point to the left of p0 with the same y coordinate.
At each point pi, i>0,
find the angle described by p-1, p0 and pi.
If two points (or more) points have the same angle,
discard the one(s) closest to p0 This is accomplished by the dot product.
Values should be between π and 0.
Sort the points in descending order, based on the angle.
Use any sort to do this.
The angle is the "key" in the sort We will now use a stack (S) to hold the
verticies of the convex hull
S.push(p0)
S.push(p1)
S.push(p2)
for i <-- 0 to m, the number of points remaining do
let pt be the point on the top of the stack
let pt-1 be the the point next to top of the stack
while pt-1, pt and pi makes a non-left turn
S.pop();
S.push(pi)
All we need to do now is to determine if we are turning left or right.
This is accomplished via the cross product.
In this case, we will define the cross product to be
u×v = uxvy-uyvx
If the cross product is negatiive, we are turning left.
If the cross product is positive, we are turning right.
An example will help
p0 = (1,2)
p1 = (2,0)
p2 = (3,1)
u = p2p0 = <3-1,1-2> = <2,-1>
v = p1p0 = <2-1,0-2> = <1,-2>
u×v = (2)(-2) - (-1)(1) = -4 +1 = -3 => left hand turn