Checking if point is in triangle - problems with precision
in
Contributed Library Questions
•
2 years ago
Hi all,
I am trying to move agents from within one triangle to another in 2d. I am currently achieving this by looping through the triangles edges, checking for an intersection, and moving to the corrosponding edge on the new triangle. I then perform a containment check to see whether the agent should move in one of 2 directions.
However, I am getting some problems when my agent is very close to the triangles corner. Ideally I want to test for containment within the triangle by placing my agent on an edge of the triangle, and then moving it in each of the two possible vectors by an infinitesimally small amount to test containment, to avoid the possibility of the movement causing the agent to 'skip around the corner' of the triangle. But when I try scaling the vectors like so, the isInTriangle method doesnt return true. Any ideas?
Thanks in advance.
I am trying to move agents from within one triangle to another in 2d. I am currently achieving this by looping through the triangles edges, checking for an intersection, and moving to the corrosponding edge on the new triangle. I then perform a containment check to see whether the agent should move in one of 2 directions.
However, I am getting some problems when my agent is very close to the triangles corner. Ideally I want to test for containment within the triangle by placing my agent on an edge of the triangle, and then moving it in each of the two possible vectors by an infinitesimally small amount to test containment, to avoid the possibility of the movement causing the agent to 'skip around the corner' of the triangle. But when I try scaling the vectors like so, the isInTriangle method doesnt return true. Any ideas?
- vel = N.copy();
vel.rotate(angleA);
//check to see if velocity pushes away from face - // - this is where things break, I cannot scale the vel
- //vector to less than around 0.1 of a unit or things break.
- //but ideally this is tiny, like 0.0001
Vec2D push =loc.add(vel.scale(0.1));
Vec2D a = onFace.a.to2DXY();
Vec2D b = onFace.b.to2DXY();
Vec2D c = onFace.c.to2DXY();
if(push.isInTriangle(a,b,c)){
}else{
//reverse vector relative to edge
vel = N.copy();
vel.rotate(angleB);
}
Thanks in advance.
2