CodeCat

Game development and others.

Line Representations 1

| Comments

When doing calculations on the computer, the first thing to know is how to represent data. Depending on the kind of calculations one does, some representations may be easier to work with than another. Geometric lines, in particular, has many representations (even for such a simple concept!). I’ll list down the representations that I know and describe them in detail. Note that I’m assuming that we’re working in Euclidean geometry.

Slope-intercept

This is what is often taught in highschool. One important detail to this representation that is often skipped is that this is a scalar function which is why it is often written as . This makes analysis simple (straight integration and differentiation works). Moreover, in the case of a line, the function is a bijection which means that you can easily get the inverse.

The form requires only two numbers for storage: the slope and y-intercept . However, the problem with this form is that this cannot represent vertical lines (i.e. for some constant ). Moreover, it can only represent lines going in one direction: from left to right. While this might not seem so much of a big deal some geometric algorithms need a notion of line direction or “line sides” (i.e. positioned rays). You actually see the issue of “line sides” when you get exercises that requires you to graph or . You’ll end up shading the “top” or “left” of the line with the first inequality and the “bottom” or “right” with the second. However, you’ll notice that if you want to represent this, you’ll end up having to store an additional piece of information: the inequality.

Two points

Another form taught in highschool is using two points to represent a line. While a line contains infinitely many points, only two points are required to fully determine a line. The nice thing about this is that it can actually represent any line in the Euclidean plane, even vertical lines. Just set for some constant and set . The non-equality restriction is to prevent collapsing the line into a singularity.

This form requires 4 numbers for storage. While you can choose any two points in a line, it is recommended that you choose two points which are not too far and not too near to each other and both close to 0 to prevent numerical instabilities in computation.

As a bonus, if you take the ordering of points into consideration, you can use it to represent lines with directions by just changing their order. For example, a line going left to right could be represented by while a line going from right to left could be represented by . Moreover, this form can also represent line segments whose endpoints are the two specified points.

The problem with this representation is that this is hard to directly work with; you don’t have an actual equation that describes the relationship of the two points. More often than not, you’ll be converting this to other representations to do calculations.

Parametric (Point + vector)

This is basically an extension of the slope-intercept form. Instead of directly placing in the function , we turn into a function, say where , and change to be also dependent on . The second form of the parametric equation is the same thing but written in vector notation.

Like the two-point form, this also requires 4 numbers for storage. is the “starting point” of the line and is the direction the line is heading. For lines, can be any point in the line and can be of any magnitude. Also, like the two-point form, this form describes the direction of the line, e.g. describes a vertical line going up while describes a vertical line going down.

If we implement some restrictions, particularly on , this form can be used to represent positioned rays and line segments.

  • Restricting the range of gives a positioned ray that starts at . This means that is restricted to the starting point of the segment.
  • Further restricing the range of gives a line segment that starts at and ends at . This means that in addition to the restriction on , should also be scaled according to the length of the line segment.

There are two more forms that I’m gonna tackle in the next article.

Comments