Math Help?

dfepstein at comcast.net dfepstein at comcast.net
Fri Apr 30 17:56:54 EDT 2010



I haven't worked this out, but FWIW: 



Draw a vertical line from point X,Y and determine the value of y at the points, if any, that your line crosses each of the triangle's 3 line segments.  It looks as if X,Y is within the triangle if 

-- at least one intersecting point exists, and 

-- Y is not greater than the greatest y value among those existing points, nor less than the least y value among those existing points. 



Try sketching a few cases to see this.  If this is right, you'd need to make 3 calls to something like 



function yOnASegment x1,y1,x2,y2,x0 

if (x0 >= x1 and x0 <= x2) or (x0<=x1 and x0>=x2) then -- the line segment includes x0, and we want to find y0: 

  put (y2-y1)/(x2-x1) into s -- slope; but need to provide separately for the case where x2=x1 

  return y1+s*(x0-x1) -- not sure I've considered all possible orderings of the points here, but you get the idea 

end if 

return empty -- x0 isn't on the segment 

end yOnASegment 



David Epstein


More information about the use-livecode mailing list