I used your question and the approaches you shared to solve the same problem which I was also having. It works nicely. I share my piece of code in processing for any future queries. Thanks.
// generate a random amount of points
PVector [] points = new PVector[1000];
// the list of points for a drawable edge
ArrayList<PVector> edgePnts = new ArrayList<PVector>();
PVector oldViewer ;
void setup(){
size(800,400);
for(int i =0; i< points.length;i++){
points[i]=new PVector(random(width), random(height));
}
oldViewer= new PVector(0,0);
}
void draw(){
background(255);
noStroke();
// turning the arraylist of vectors into an array of vectors
PVector[] polyVerts = edgePnts.toArray(new PVector[edgePnts.size()]);
for(int i =0; i< points.length;i++){
if(edgePnts.size()>0){
if(pnInPoly(edgePnts.size(),polyVerts,points[i])<0){
fill(0,255,0);
ellipse(points[i].x,points[i].y, 10,10);
}else{
fill(0);
ellipse(points[i].x,points[i].y, 5,5);
}
}else{
fill(0);
ellipse(points[i].x,points[i].y, 5,5);
}
}
if(edgePnts.size()>0){
fill(255,0,0);
stroke(255,0,0);
for(int i =0; i< edgePnts.size();i++){
// for(PVector p : edgePnts){
ellipse(edgePnts.get(i).x,edgePnts.get(i).y,2,2);
if(i>0){
line(edgePnts.get(i).x,edgePnts.get(i).y,edgePnts.get(i-1).x,edgePnts.get(i-1).y);
}
}
}
if (mousePressed){
PVector viewer = new PVector(mouseX,mouseY);
if(oldViewer.dist(viewer)>10){
edgePnts.add(viewer);
oldViewer = viewer;
}
}
}
void keyPressed(){
if(key == 'r' || key == 'R'){
reset();
}
}
void reset(){
edgePnts = new ArrayList<PVector>();
for(int i =0; i< points.length;i++){
points[i]=new PVector(random(width), random(height));
}
}
// the testing function to check if the point in case is inside the polygon
int pnInPoly(int nvert, PVector [] vert, PVector test){
int i, j;
int c = 1;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((vert[i].y>test.y) != (vert[j].y>test.y)) &&
(test.x < (vert[j].x-vert[i].x) * (test.y-vert[i].y) / (vert[j].y-vert[i].y) + vert[i].x) )
c = c * (-1);
}
return c;
// if c < 0 means it is inside
}