Search code examples
opengl2dcurve

OpenGL how to check if a point is inside a area made of Bernstein curve


I want to check if a specified corrdinate is inside an area closed under curve. My curve line is generated as follows:

float CtlPoint[] =
{
    0, -0.3, 0,
    0.15, -0.25, 0,
    0.6, -0.2, 0,
    0.2, 0.20, 0,
    0.10, 0.25, 0,
    0.05, 0.5, 0,
    0.02, 0.6, 0,
    0.0, 0.8, 0,
   -0.02, 0.6, 0,
   -0.05, 0.5, 0,
   -0.10, 0.25, 0,
   -0.2, 0.20, 0,
   -0.6, -0.2, 0,
   -0.15, -0.25, 0,
    0, -0.3, 0
};

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 15, CtlPoint);
glEnable(GL_MAP1_VERTEX_3);

glBegin(GL_LINE_STRIP);
for (int t = 0; t <= 100; ++t){
    glEvalCoord1f(static_cast<float>(t) / 100);
}
glEnd();

I randomly generate 2 float numbers x and y and want to test a coordinate using those two values is inside the curve line specified above.


Solution

  • Capture the eval output via your favorite method and use a standard point-in-polygon test.