Go to Bottom of Page

[Previous Section] [Next Section]

LECTURE 3
Chee Yap
BASIC COMPUTATIONAL GEOMETRY

BASIC COMPUTATIONAL GEOMETRY

Two general remarks: first, we ought to say that our first tangible goal is to understand a very interesting data set called the TIGER Dataset, freely available from the US Census Bureau. In our visualization project webpage http://cs.nyu.edu/visual/, we have provided a TIGER resource page (click "project" then click "Tiger Tools"). For a demo of this data set, you can instead click "demos" and then click "GIS-on-the-Web". [Please do this before continuing]

As preparation for our discussion of the TIGER Dataset, we need a common vocabulary of geometry. All of us have some geometric background from high school and college calculus. What is perhaps new is the computational aspects of this, which is part of an active research area in Computer Science called Computational Geometry.

[Previous Section] [Next Section]

1   Lines

Most of what we say will be in 2D, with occasional reference to 3D.

What is a Line?  

A point p is given by a pair of real numbers (x,y) \mathbb R2. We often write ``p[x,y]'' to specify the point (x,y) as well as to name it as p.

What about a line l which we often think of as comprising an infinite number of points? Well, we can still finitely specify it by three real numbers (a,b,c) \mathbb R3, because a point (x,y) belongs to this line l iff it satisfies a linear equation of the form
ax+by+c=0.
Again we might write ``l[a,b,c]'' to specify the line as well as to name it as l.

Example. lx[0,1,0] specifies lx to be the line whose equation is y=0, and this is just the x-axis. Again, the line l45 with slope 45° and passing through the origin is given by l45[1, 1, 0].

How unique is the parameters a,b,c for a line? First of all, note that a, b, c cannot ALL be zero. Next, it is clear that we can multiply or divide divide them by any common non-zero number and still get the same equation. E.g., if l1[a,b,c] and l2[a/2, b/2, c/2] and l3[5a, 5b, 5c] represent the same line. In particular, we can change the sign of all the parameters of a line, as this amounts to multiplying by 1.

To make it unique, we can specify c is either 0 or 1. If c is 0 then we can insist that b be either 0 or 1. EXERCISE: Show that these two rules ensure uniqueness.

Directed Line.  

Geometrically, a line is a set of points. Algebraically, we represent it by an equation - but this immediately introduce some extraneous information. For instance, the line l[a,b,c] and the line l[2a, 2b, 2c] are the same. Thus, up to multiplication by a non-zero constant, the line equation does not change. But there is one bit of extra information that is actually useful. This bit of information specifies the direction of a line. A line can have one of two directions (hence one bit of information), and this gives rise to two versions of the line. A line with this extra bit of information is called a directed line.

Equivalently, the extra bit of information distinguishes the two half-planes to either side of the line. One side can now be called left-side, and the other the right-side. Following a human-centric convention, if you look along the direction of the line, the left-side is to your left. This convention can be encoded in algebraic terms using the next definition:

Given a directed line l[a,b,c] and a point p[s,t], we say p is left of l iff as+bt+c > 0. It is right of l iff as+bt+c < 0. Otherwise it is on l.

FIGURE HERE of DIRECTED LINE.

Example. The x- and y-axes are examples of directed lines. We had defined lx[0,1,0]. According to our definition, a point (s,t) is left of lx iff t > 0, and left of lx iff s > 0. This agrees with our usual convention about the x-axis. What about the y-axis? In order to get the direction correct, we must define the y-axis to be ly[1,0,0].

What we have just shown is that when l[a,b,c] are viewed as a directed line, then l[a,b,c] represents the same line with the opposite orientation. So, for oriented lines, the line is invariant under multiplication of all its parameters by a POSITIVE constant.

The Geometric Meaning of Directed Lines.   But so far we have only formalized the concept of directed lines in terms of its representation (namely, through its equation). We have relied on geometric intuitions of the reader when discussing examples. How can we formalize such ideas in some intrinsic geometric terms? We claim: choosing a direction for a line amounts to choosing a special kind of total ordering of the set of points on the line. Let p \preceq q denote this ordering relation for any two points p,q on the line. The special property we impose on the ordering is this:

If p\preceq q and q\preceq r, then as we move from p to r along the line, we must pass through q.
Because of this property, it can be seen that once we pick two distinct points p0, p1 on the line and specify their relation (either p0\preceq p1 or p1\preceq p0), then the total ordering is completely determined. Hence, there are only two possible orderings with the special property. Moreover, these two orderings \preceq1, \preceq2 are opposites in the sense that for all p and q, we have p\preceq1 q iff q\preceq2 p.

Parametrized Lines  

Our ordering \preceq until now is abstract. But given p and q, how do we computationally determine whether p\preceq q holds? Our goal is to encode this ordering as an ordering of the real numbers; this would allow us to computationally reduce the relation p \preceq q to the comparison of two real numbers! To do this, we introduce the concept of a parametric line.

Lines can be regarded as a one-one continuous function l:\mathbb R\mathbb R2 such that {l(t): t \mathbb R} is the set of points on the line. We call such a function l a parametrized line and l(t) is the point on the line corresponding to the parameter value t. Since l is one-one, it means there is a unique real number associated with each point of the line.

Note that parametrized line automatically gives rise to a directed line: the relation \preceq is given by s t iff l(s)\preceq l(t).

Here is an simple way to specify a parametrized line: if p and q are distinct points on l, we define the line l(p,q) such that l(0)=p and l(1)=q as follows:
l(t) = p + t(qp).
You can check that l(0)=p and l(1)=q. Also, l(2)=2q + p, etc.

For parametrized line l(p,q) we have a different way of telling if a point r is left or right of l:

[Previous Section] [Next Section]

2   Linear Algebra

Following in the footsteps of Descartes, we must use algebra if we are to make our geometric intuitions rigorous. We have already seen this in our use of linear equations to represent lines. Here we will quickly review the basic facts, posed in 2 dimensions only. In Algebra, instead of points, we have vectors. A vector v is indistinguishable from a point in some sense: it is also represented by a pair of real numbers, v=(x,y) \mathbb R2. We can add and subtract vectors: if u=(x,y) then v±u = (x±x, y±y). We can multiply them by a real number c, where cv = (cx, cy). When x=y=0, we also write v=\0, and this is called the zero vector.

We can call v a 2-vector, to draw attention to the fact that it has two components, and more generally we can have ``n-vectors'' for any natural number n.

In general, we need to deal with m×n matrices which are rectangular array of numbers. Here m is the number of rows, and n the number of columns. We can also say our vectors and matrices are real when their entries are all real numbers. A vector is a special kind of matrix, namely a 2×1 matrix. Thus we view v as a column-vector - this distinction when we multiply v by a matrix shortly. Strictly speaking, we ought to write v=(x,y)T where the superscript T indicates the transpose operation on a matrix. But we will be sloppy to avoid this clutter (but the reader will be asked to do the mental transposition when the situation requires one).

We assume the reader knows how to multiply two general matrices: if A and B are m×n and n×p matrices then their produce AB is a m×p matrix. In particular, a 2-vector v can can be multipliee with a 2×2 matrix A. Let
A =

a
b
c
d


denote such a matrix. Then Av is the vector (ax+by, cx+dy). A special matrix is when a=d=1 and b=c=0. This particular matrix is denoted I, called the identity matrix. We check that Iv = v.

The determinant of A is given by adbc. If this number is zero, then A is singular and otherwise non-singular. To be singular means that the first column of A is a multiple of the second column of A. When A is non-singular, we can compute its inverse denoted A1. This is given by
Aa =  1

adbc


d
b
c
a


.
One can check that AA1 = A1A = I.

If b is a vector and A a matrix, the process of finding the vector v such that
Av= b
(1)
is called solving for v, or solving a linear system of equations. Thus, v is treated as the unknown in (1). We must recogize the fact that our equation may have no solution, i.e., no real vector v exists. Here is the general theorem:

Theorem 1 There are three cases in solving the system (1)
(i) A is non-singular. There is a solution given by v = A1b.
(ii) A is singular and there is no solution.
(iii) A is singular and there is a solution v0. Let u0 be a non-trivial solution of Av =\0 (the homogeneous equation). Then the set of all solutions is given by {v0+λu0: λ \mathbb R}.

For case (iii), using the fact that A is singular, the two columns of A are linearly dependent. If the two columns are w1, w2, then αw1+βw2=0 for some α, β. We may choose u0=(α,β).

Intersection of Lines.  

Let us use this theorem immediately! Suppose l[a,b,c] and l[a,b,c] are two lines. We want to compute their intersection. Let us view the lines as sets of points, and so their intersection is a set of points. In general, we expect to get a single set (i.e., a set with one point). Call this the regular case. But we must get the empty set, or even an infinite set (this happens when the two lines are coincident).

In the regular case, let p[X,Y] denote their intersection point. How do you actually compute X,Y from l, l? Well, we have
aX + bY +c
=
0,
aX + bY +c
=
0.
Rewriting this in matrix form, in our usual form,


a
b
a
b


·

X
Y


=


c
c


A·v
=
c

where A = [
a
b
a
b
], v = [
X
Y
] and c = [
c
c
]. As in the theorem the solution is


v= A1 c.

We gain some insights on the uncanny correlation between geometry and algebra: Since the regular case has a unique solution, our theorem tells us this corresponds to A being non-singular, and conversely. When A is singular, we either get two coincident lines l = l or two distinct but parallel lines.

Projecting a Point to a Line  

Let us solve another basic problem. Suppose the line l is defined by two points p0 and p1. Let q be another point, which we must assume is not on l. Our goal is to compute the point p on l that is closest to q. This point p is called the projection of q on l.

So write p=(X,Y) where X, Y are unknowns. We just have to set up two equations that p must satisfy.

(1) The first equation says that the vector pq and p1p0 are perpendicular to each other. In general, two vectors u, v are perpendicular if their scalar product u·v is zero. The scalar product is defined by
u·v = (u.x×v.x) + (u.y×v.y).
Hence our first equation is
(pq)·(p1p0) = 0.
(2)

(2) The second equation says that p lies on the line l. This amounts to our orientation2d predicate discussed in class: orientation2d(p0, p1, p)=0. In terms of 2×2 determinants, this is the same as
det
[ p1p0, pp0] = 0.
(3)

We can stop here, and we ask the student to set up the above two equations into a linear system of the form (1) and solve it.

NOTE: This process, though tedious, is routine. Let us demonstrate the process mainly to verify this claim. It amounts to putting the above two equations into a more verbose form: First, Equation (2) is expanded into
(Xq.x)(p1.xp0.x)+(Yq.y)(p1.yp0.y)
=
0
X(p1.xp0.x)+Y(p1.yp0.y) q.x(p1.xp0.x)q.y(p1.yp0.y)
=
0
Next, Equation (3) becomes
(p1.xp0.x)(Yp0.y) (p1.yp0.y)(Xp0.x)
=
0
X(p1.yp0.y) + Y(p1.xp0.x) p0.y(p1.xp0.x) + p0.x (p1.yp0.y)
=
0
Rewriting both equations as a single matrix equation,




p1.xp0.x
p1.yp0.y
p0.yp1.y
p1.xp0.x


·

X
Y


=


q.x(p1.xp0.x)q.y(p1.yp0.y)
p0.y(p1.xp0.x) + p0.x (p1.yp0.y)


This has the usual A x=b form of linear systems of equations, which you can implement in your programs.

The upshot is this: we see that the vector/matrix notation is a highly compact way of storing the same information which, using scalar variables, is both messy and not highly memorable. Henceforth, whenever possible, we should try to use vectors and matrices to describe our manipulations.

[Previous Section] [Next Section]

3   Line Segments

A line segment is represented by a pair of points (p,q). We can again think of it as oriented or not, but the default is to give it an orientation. We can also think of it as open or closed (should it include its end points). The default is closed.

Here is one difference between a segment s and a line L: given another point q, we want to find the point in s that is closest to q. For a line L, we just project q to L. For a segment s, this may not be the right answer.

[Previous Section] [Next Section] Go to Top of Page


File translated from TEX by TTH, version 3.01.
On 30 Apr 2003, 17:39.