Search code examples
geometrycomputational-geometrytriangularrobust

2D orientation test barycentric coordinates


If I have an ordered 3-tuple of points in integer barycentric coordinates, how do I test orientation on them? (I want to know if the points are collinear, form a left turn or a right turn)

The "algorithm" has to be quite robust so I don't want to convert the coordinates to cartesians.

For cartesians, there is a very nice way to determine this using only multiplication and addition: https://www.cs.cmu.edu/~quake/robust.html

There is a similar way to find out if three points are collinear here, but I don't know if I can use it for this application: http://web.evanchen.cc/handouts/bary/bary-short.pdf


Solution

  • As the last paper says, for CCW base triangle ABC signed area for PQR is positive for CCW order (footnote at page 1), so triplet P, Q, R makes left turn if determinant

     x1  y1  z1
     x2  y2  z2
     x3  y3  z3
    

    has positive value (theorem 10), and points are collinear for zero determinant