views:

49

answers:

1

Hi, I'm looking to write a little comp-geom library, in Ruby.

I'm about to write the code for lines, and was wondering which line equation I should use:

  • ax + by + c = 0
  • r + tv (where r and v are vectors)

Thanks.

+1  A: 

If using the classical equations is not a requirement, I'd suggest an array of four co-ordinates: xStart, yStart, xEnd and yEnd.

In case you need to make the line position dynamic, you could use an array of two parameters: alpha and radius. The former represents radial rotation relative to the horizontal axis and the latter is the length of line.

Yet another option would be vectors in the form of (X;Y).

Samples in C:

int endpointsLine[4] = {0, 0, 30, 40};
double radialLine[2] = {5.35589, 50};
int vectorLine[2] = {30, 40};

The "endpoints" format is fully compatible with modern line-drawing algorithms, such as Xiaolin Wu's line algorithm and Bresenham's line algorithm but it represents specific screen co-ordinates which is not the case with "radial" and "vector" format.

Saul