10

If i have a,b,c point with x,y in form of vectors than how can I find collinear points..

fabs((b.x_-a.x_)*(c.y_-a.y_)-(c.x_-a.x_)*(b.y_-a.y_) its used like this.. how its like this?

winwaed
  • 7,645
  • 6
  • 36
  • 81
  • 6
    There will be numerical instabilities with that approach, consider a more robust process, for example the distance of C from the line (not line-segment) AB and that distance being less than some tolerance. –  Dec 29 '10 at 17:31

3 Answers3

6

The differences give you the internal vectors from a to b, and a to c.

The multiplications then represent the cross product between these two vectors. The cross product is proportional to the sine of the angle between these two vectors. The sine between these two vectors is zero when the points are collinear.

Your particular formula is a 2d contraction of the more conventional 3d cross product. See: http://en.wikipedia.org/wiki/Cross_product

winwaed
  • 7,645
  • 6
  • 36
  • 81
3

You can interpret the formula as a cross product (as explained in winwaed's answer), or you can interpret it as being about the slopes of the vectors b-a and c-a, as explained in this answer.

Community
  • 1
  • 1
brainjam
  • 18,863
  • 8
  • 57
  • 82
3

fabs((b.x_-a.x_)*(c.y_-a.y_)-(c.x_-a.x_)*(b.y_-a.y_) is the cross product.

Note that:

fabs(crossProduct( (b-a), (c-a) ) ) == length(b-a)*distance of c from the line (a,b)

Hence is zero if and only if only when c lies on the line (a,b), only providing a,b are distinct.

I'd be interested to hear comments, or better examples, as to why this might be "unstable". I always thought it was quite robust.

Keith
  • 6,756
  • 19
  • 23