2

I saw a lot of posts describing how to find if the point lies outside or inside. But I want to know if there's a way to know if the point is in the edge of the triangle.

The equation should have 4 parameters (p,x,y,z), the point which I try to discover lies on the edge and three other points that create the triangle

When I saw on edge, I mean on any of the segments, given a triangle "on edge" is any of the lines that create it

coder
  • 12,832
  • 5
  • 39
  • 53
  • possible duplicate of http://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle –  Oct 07 '16 at 03:00
  • But that only determines if it's inside or outside the triangle, I want to know if the point is rigth in an edge –  Oct 07 '16 at 03:02
  • Write the equations of the sides. See if it makes them true. Or simpler: take slopes when it is connected to each vertex and see if any match. – Jeremy Kahan Oct 07 '16 at 03:10
  • Also, if you're thinking of sides as segments (not lines), check betweenness. – Jeremy Kahan Oct 07 '16 at 03:16
  • see http://stackoverflow.com/questions/11907947/how-to-check-if-a-point-lies-on-a-line-between-2-other-points – Jeremy Kahan Oct 07 '16 at 03:19
  • https://www.desmos.com/calculator/rp0xnhzawy Maybe you need this. –  Oct 07 '16 at 03:27
  • @LearnHowToBeTransparent that's what I want to know, if the point I choose if one of those who conform the segment –  Oct 07 '16 at 03:36
  • How do you know if a point is on a segment? You need to determine if point is on either one of three segments. – 0kcats Oct 07 '16 at 03:59

2 Answers2

2

What does on the edge mean ?

Even if your end points and the point you pick are integers the equation of line is not. No point will ever be on the line to infinite precision (except for obvious cases)

It really only makes sense to say the point is within some small distance of the line. See Shortest distance between a point and a line segment for equations.

Community
  • 1
  • 1
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
2

When you calculate postition of the point relative to triangle edge with function from linked answer:

float sign (fPoint p1, fPoint p2, fPoint p3)
{
    return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
}

then zero sign value denotes that point lies exactly on the edge.

(More exactly - on the line containing edge. Signs for two other edges show whether point is between vertices)

If you need some tolerance level to compensate floating-point errors, just compare absolute "sign" value with triangle area.

DoubledTriangleArea = Abs(sign(v1, v2, v3)
if (Abs(sign(p, v1, v2)) / DoubledTriangleArea < SomeSmallValue)
    p lies near v1-v2 edge
MBo
  • 77,366
  • 5
  • 53
  • 86