// public-domain code by Darel Rex Finley,
// 2010. See diagrams at http://
// alienryderflex.com/point_left_of_ray
bool isPointLeftOfRay(double x, double y, double raySx, double raySy, double rayEx, double rayEy) {
double theCos, theSin, dist ;
// Translate the system so that the ray
// starts on the origin.
rayEx-=raySx; rayEy-=raySy;
x -=raySx; y -=raySy;
// Discover the ray’s length.
dist=sqrt(rayEx*rayEx+rayEy*rayEy);
// Rotate the system so that the ray
// points along the positive X-axis.
theCos=rayEx/dist;
theSin=rayEy/dist;
y=y*theCos-x*theSin;
// Return the result.
return y>0.; }
|